Simple Passing variable obstacle!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
cap2cap10
Forum Contributor
Posts: 158
Joined: Mon Apr 14, 2008 11:06 pm

Simple Passing variable obstacle!

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Simple Passing variable obstacle!

Post by AbraCadaver »

In the first form:

Code: Select all

<input type="hidden" value="<?php echo $userID; ?>">
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
cap2cap10
Forum Contributor
Posts: 158
Joined: Mon Apr 14, 2008 11:06 pm

Re: Simple Passing variable obstacle!

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Simple Passing variable obstacle!

Post 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);
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
cap2cap10
Forum Contributor
Posts: 158
Joined: Mon Apr 14, 2008 11:06 pm

Re: Simple Passing variable obstacle!

Post 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?
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Simple Passing variable obstacle!

Post 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");
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply