1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Help with id variable?

Discussion in 'PHP & Perl' started by Krazie, Jan 4, 2012.

  1. Krazie

    Krazie Jr. VIP Jr. VIP Premium Member

    Joined:
    Aug 27, 2009
    Messages:
    266
    Likes Received:
    197
    Home Page:
    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: Jan 4, 2012
  2. hameem

    hameem Elite Member

    Joined:
    Jul 21, 2011
    Messages:
    1,880
    Likes Received:
    985
    Location:
    221B Baker Street
    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.
     
    • Thanks Thanks x 1
  3. headhunterzz

    headhunterzz Registered Member

    Joined:
    Mar 30, 2010
    Messages:
    95
    Likes Received:
    21
    Occupation:
    IM at home
    Location:
    France
    Home Page:
    Foreach with select and where?
     
  4. paincake

    paincake Power Member

    Joined:
    Aug 18, 2010
    Messages:
    716
    Likes Received:
    3,099
    Home Page:
    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 {
    }
     
    • Thanks Thanks x 1
    Last edited: Jan 4, 2012