Note that there are some explanatory texts on larger screens.

plurals
  1. POLoosing userid in session when redirecting to page after inserting data from useing PHP
    text
    copied!<p>I need some help on this problem I have, 2 PHP files, one is a form the other the PHP code to insert the data to the database. I am using a userID in a session to keep the data entered for the same user, my problem is after I submit the data to the database my page have to redirect to another page in the same session with the same userID but display the entered data in the table, but every time I submit it goes to the right page but without the userID, (437465375.php?userID=) if I put the user id in on the end (437465375.php?userID=33) it goes to the right page displaying the data enter in the table.</p> <p>Here is the code for the form:</p> <pre><code> &lt;div class="posttext"&gt; &lt;p&gt;&lt;strong&gt;PRIMARY INFORMATION TO BE FURNISHED BY A TAXPAYER AS REQUIRED BY SARS.&lt;/strong&gt;&lt;/p&gt; &lt;?php if (!isset($_SESSION['userID'])) { echo " &lt;form method='post' id='contatti' action='savetrip1.php?userID='" . $_GET['userID']."'&gt;"; ?&gt; &lt;div id="contactform"&gt; &lt;?php echo "&lt;p&gt;&lt;h2&gt;&lt;strong&gt;Kilometre Recording&lt;/strong&gt;&lt;/h2&gt;&lt;/p&gt;"; echo "&lt;div class='commentfield'&gt;"; echo "&lt;label for='author'&gt;Work Km Travelled ( Total Km only not Speedomiter meter reading): &lt;/label&gt; &lt;input type='text' value='".$row['travelledKm']."' name='travelledKm' id='TravelledKm' /&gt;"; echo "&lt;/div&gt;"; echo "&lt;div class='commentfield'&gt;"; echo "&lt;label for='author'&gt;Date: YYYY-MM-DD &lt;/label&gt;&lt;input type='text' value='".$row['LoggedDate']."' name='LoggedDate' id='LoggedDate' /&gt;"; echo "&lt;/div&gt;"; echo "&lt;p&gt;&lt;h2&gt;&lt;strong&gt;Business Travel Details&lt;/strong&gt;&lt;/h2&gt;&lt;/p&gt;"; echo "&lt;div class='commentfield'&gt;"; echo "&lt;label for='author'&gt;From Where did you Travel: &lt;/label&gt; &lt;input type='text' value='".$row['fromk']."' name='fromk' id='fromk' /&gt;"; echo "&lt;/div&gt;"; echo "&lt;div class='commentfield'&gt;"; echo "&lt;label for='author'&gt;To Where did you Travel: &lt;/label&gt; &lt;input type='text' value='".$row['tok']."' name='tok' id='tok' /&gt;"; echo "&lt;/div&gt;"; echo "&lt;div class='commentfield'&gt;"; echo "&lt;label for='author'&gt;Reason: &lt;/label&gt; &lt;input type='text' value='".$row['Reason']."' name='Reason' id='Reason' /&gt;"; echo "&lt;/div&gt;"; echo "&lt;div class='commentfield'&gt;"; echo "&lt;label for='author'&gt; Fuel &amp;amp; Oil Costs (R): &lt;/label&gt; &lt;input type='text' value='".$row['Fuel']."' name='Fuel' id='Fuel' /&gt;"; echo "&lt;/div&gt;"; echo "&lt;div class='commentfield'&gt;"; echo "&lt;label for='author'&gt;Repairs &amp;amp; Maintenance Costs (R): &lt;/label&gt; &lt;input type='text' value='".$row['Repairs']."' name='Repairs' id='Repairs' /&gt;"; echo "&lt;/div&gt;"; echo "&lt;div class='contactbutton'&gt;"; echo "&lt;input type='submit' class='contact-button' name='submit' id='invia'value='Save Trip' /&gt;"; echo "&lt;input type='reset' class='contact-button' name='clear' value='Clear Input' /&gt;"; echo "&lt;/div&gt;"; echo "&lt;/form&gt;"; } ?&gt; &lt;/div&gt;&lt;/div&gt; &lt;/div&gt; </code></pre> <p>And here is the php code for submiting the data to the mysql database:</p> <pre><code> &lt;?php session_start('userID'); $host = "localhost"; $db = "database"; $user = "user"; $pass = "pass"; $userID=$_SESSION['ID']; $travelledKm=$_POST['travelledKm']; $LoggedDate=$_POST['LoggedDate']; $fromk=$_POST['fromk']; $tok=$_POST['tok']; $Reason=$_POST['Reason']; $Fuel=$_POST['Fuel']; $Repairs=$_POST['Repairs']; $conn = mysql_connect($host, $user, $pass); mysql_select_db($db) or die(mysql_error()); if (isset($_POST['submit']) == true) { $query = "INSERT INTO `webimckr_lockbook`.`trip_log`(`userID`,`LoggedDate`,`travelledKm`,`fromk`,`tok`,`Reason`,`Fuel`,`Repairs`)VALUES ('$userID','$LoggedDate','$travelledKm','$fromk','$tok','$Reason','$Fuel','$Repairs')"; $result=mysql_query($query) or die(mysql_error()); if($result){ header("Location: 437465375.php?userID=".$_GET['userID'].""); } else { echo "ERROR"; } } ?&gt; &lt;?php // close connection mysql_close(); ?&gt; </code></pre> <p>I am very new to PHP and Mysql and learning on my own, please assist me with this so that I can understand it and for future use.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload