...

View Full Version : Pulling ID from MySQL and using as a hidden field



dtw
11-29-2006, 09: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

Tyree
11-30-2006, 12:07 AM
If it's all in the same db, just in different tables, just query the table that has the ID and assign the value to a variable. That is provided that you have a way of targetting the desired row in the database table.

<input type="hidden" name="id" value"<?php print $IDvalue; ?>" />

You may have to elaborate a bit on this scenario.

Is the ID that will be added taken from a database of current users?
In other words what does the ID have to be matched with that the user is inputting?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum