Help with id variable?

Krazie

Regular Member
Joined
Aug 27, 2009
Messages
268
Reaction score
202
I'm wondering how I would do this. I have a sql db set up, with id as an auto_increment.
I want to have it take page1.php and when it submits the forms on that page and assign an id into the table. For example it would assign it id 2. (I have this much done)

The part I'm having a problem is then it would take that id and go to page2.php?id=2, then page3.php?id=2 etc..

How would I get it to pass the id that it submitted on page 1?
 
Last edited:
I understand that after submitting the form on page1.php, it stays on page1.php. It doesn't end up in page2 or page3. If that is correct, you can do 3 things.

1) Retrieve the id from the table in database on page2 or any other page for that matter
2) Store the id in a session and then retrieve it on other pages
3) Set the navigation on page1.php in a form so that clicking on "next" or "page2" or whatever would actually be clicking on. A submit button. Keep the id's value in a hidden variable in that form and retrieve it on the next page.

The session thing will work quicker than the database one.
 
One way to do this would be:
PHP:
$myid = 123456; 
//or
if (isset($_POST['yourtableid']){
$myid = $_POST[yourtableid]; //make sure to secure this if you're gonna be writing it to database or outputting as html
}
setcookie('myid',$myid,time() + (86400 * 30)); //the last part means the cookie will last for 30 days
If this is a unique user id, it should preferably be set at the beginning of the file. You can wrap the above lines in this:
PHP:
if  (!isset($_COOKIE['myid']){
}

You don't really need to create multiple php files for multiple steps, you could just do simple navigation in a single file, like this:
PHP:
if (isset($_POST['currentstep']){
if ($_POST['currentstep'] == '1'){
//print form 1
}
elseif ($_POST['currentstep'] == '2'){
//print form 2
}
elseif ($_POST['currentstep'] == '3'){
//print something else
}
}
else {
}
 
Last edited:
Back
Top