dtw
11-29-2006, 08:26 PM
I have a multi-page (multi-form) survey and want to make sure that each form can be connected to the others via some sort of ID.
The login page asks for first, last name, username, newpassword, confirmed password, with the login form being processed by the following script:
<?php
$username= "myusername";
$password="mypw";
$database = "mydb";
$host = "myhost.edu";
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$usename=$_POST['usename'];
$userpw=$_POST['userpw'];
$confpw=$_POST['confpw'];
mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "INSERT INTO imoi_login_1 VALUES (null,'$fname','$lname','$usename','$userpw','$confpw')";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
else
{
echo "Responses have been saved";
}
mysql_close();
?>
The "null" that is inserted into the table represents a placeholder for an ID variable that is added by MySQL.
Is there any way to pull this ID number from the db and use it as a hidden field on subsequent forms? :confused: This is necessary so that I can match responses from one form (saved in one table of the db) with another set of responses by the same user (saved in a different table of the db).
Thanks in advance to anyone who helps, and please include code if possible.
Many thanks.
Dave
The login page asks for first, last name, username, newpassword, confirmed password, with the login form being processed by the following script:
<?php
$username= "myusername";
$password="mypw";
$database = "mydb";
$host = "myhost.edu";
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$usename=$_POST['usename'];
$userpw=$_POST['userpw'];
$confpw=$_POST['confpw'];
mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "INSERT INTO imoi_login_1 VALUES (null,'$fname','$lname','$usename','$userpw','$confpw')";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
else
{
echo "Responses have been saved";
}
mysql_close();
?>
The "null" that is inserted into the table represents a placeholder for an ID variable that is added by MySQL.
Is there any way to pull this ID number from the db and use it as a hidden field on subsequent forms? :confused: This is necessary so that I can match responses from one form (saved in one table of the db) with another set of responses by the same user (saved in a different table of the db).
Thanks in advance to anyone who helps, and please include code if possible.
Many thanks.
Dave