Page 1 of 1

Simple Passing variable obstacle!

Posted: Mon Jan 25, 2010 12:36 pm
by cap2cap10
:drunk: Happy belated :) New Year, php technorati. I hope all is going well for you and your families. I have a simple problem. How do I pass a variable ($userID) from 1 form to another form with out using sessions? the userID was created by submission of the first form. Is it possible to use the header(location: url) to pass the variable to the next form? :banghead:

Please enlighten me!

thanks in advance,

Batoe

Re: Simple Passing variable obstacle!

Posted: Mon Jan 25, 2010 12:44 pm
by AbraCadaver
In the first form:

Code: Select all

<input type="hidden" value="<?php echo $userID; ?>">

Re: Simple Passing variable obstacle!

Posted: Mon Jan 25, 2010 12:56 pm
by cap2cap10
Ok, this the insert script that will create the userID in the mysql db:

Code: Select all

mysql_query("INSERT INTO js_login(agentID, month, pay_type, username, password, FName, MName, LName, Email, survey) VALUES ('$agentID', '$month', '$pay_type','$username', '$password',
 '$FName', '$MName', '$LName', '$Email','$survey') ") or die(mysql_error());
 
mysql_query("INSERT INTO js_account(FName, MName, LName, Email, Address, Suite, City, State, Zipcode,
Country, Hphone_1, Hphone_2, Hphone_3, Mphone_1, Mphone_2, Mphone_3, Wphone_1, Wphone_2, Wphone_3, Extension, acc_stat)
VALUES ('$FName', '$MName', '$LName', '$Email', '$Address', '$Suite', '$City', '$State', '$Zipcode',
'$Country', '$Hphone_1', '$Hphone_2', '$Hphone_3', '$Mphone_1', '$Mphone_2', '$Mphone_3', '$Wphone_1',
'$Wphone_2', '$Wphone_3', '$Extension', 'yes') ") or die(mysql_error());
 
mysql_close();
 
header("Location: profile1.php");
userID is generated on submission. Now, how would I get the new userID?

Thanks again,


Batoe

Re: Simple Passing variable obstacle!

Posted: Mon Jan 25, 2010 1:04 pm
by AbraCadaver
I'm not sure I follow you, but do you mean how to get the last auto increment id that was generated by the database from the insert?

Code: Select all

$result = mysql_query("INSERT INTO js_login(agentID, month, pay_type, username, password, FName, MName, LName, Email, survey) VALUES ('$agentID', '$month', '$pay_type','$username', '$password',
 '$FName', '$MName', '$LName', '$Email','$survey') ") or die(mysql_error());
 
$userID = mysql_insert_id($result);

Re: Simple Passing variable obstacle!

Posted: Mon Jan 25, 2010 1:32 pm
by cap2cap10
Yes, how do I pass that new userID to the next form, so that it will now where to place the form data in the mysql db?

Re: Simple Passing variable obstacle!

Posted: Mon Jan 25, 2010 1:56 pm
by AbraCadaver
cap2cap10 wrote:Yes, how do I pass that new userID to the next form, so that it will now where to place the form data in the mysql db?
This is getting hard to follow, but if by "next form" you mean profile1.php, then append it when you use header:

Code: Select all

header("Location: profile1.php?userid=$userID");