Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Mar 2005
    Posts
    240
    Thanks
    1
    Thanked 0 Times in 0 Posts

    $_SESSION to bring up a confirmation page

    Hi there
    I have a 3 page registration page where the user inputs information on 3 seperate pages.

    On page four of the registration process, I would like to bring up the fields they entered in the previous 3 pages to confirm that the info they input is correct.

    For the first 3 pages I used a $_SESSION and an insert/update script as follows to enter the info all under 1 user ID

    Page 1: $_SESSION and INSERT
    Page 2: $_SESSION and UPDATE
    Page 3: $_SESSION and UPDATE

    Now on page 4 I tried using the $_SESSION as well as a SELECT quiery to bring up the information entered in pages 1, 2 and 3 but nothing comes up?!

    I checked the DB and the information is stored there...

    Any help? Can a $_SESSION plus a SELECt work for what I'm trying to do?

    Thanks

  • #2
    Regular Coder
    Join Date
    May 2006
    Posts
    106
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes. Make sure you are doing a session_start on your page 4 so the session variable is available. Assuming you are trying to select the client with the ID field from the creation on the first page.

  • #3
    Regular Coder
    Join Date
    Mar 2005
    Posts
    240
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi Cubsfan...
    Thanks for the reply. I did put a session_start(); at the top of the page and then I did an "echo" to bring up the variables I want to select... But for some reason it doesn't come up...

    here's the code if you don't mind looking at it.

    At the top of the page:

    PHP Code:
    session_start(); 
    Then I have

    PHP Code:
    $user="xxx";
    $host="xxx";
    $password="xxx";
    $database "xxx";
    $connection mysql_connect($host,$user,$password)

    or die (
    "couldn't connect to server");
    $db mysql_select_db($database,$connection)

    or die (
    "Couldn't select database");
    $query "SELECT product FROM client WHERE ID=".$_SESSION['formID'];
    $result mysql_query($query)
    or die (
    "Couldn't execute query."); 
    Then I have an HTML table with all the fields that I am bringing back (this is static) and inside the table I call the fields in question with an "echo" statement....

    For example:

    Code:
    <td align="right" width="230">
    <p>Product:</p>
    </td>
    <td>
    <p><?php echo $product ?></p>
    </td>
    So, when I look at this page, the "Product" field is blank... meaning for some reason it doesn't bring back the quiery

  • #4
    Regular Coder
    Join Date
    May 2006
    Posts
    106
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by losse
    Hi Cubsfan...

    PHP Code:
    $user="xxx";
    $result mysql_query($query)
    or die (
    "Couldn't execute query."); 
    You have to actually do something to get the data beyond just doing the query, and then set your variables accordingly.

    PHP Code:
    $row mysql_fetch_array($result);
    $product $row['product']; 
    and then you can use the $product variable in your HTML.

  • #5
    Regular Coder
    Join Date
    Mar 2005
    Posts
    240
    Thanks
    1
    Thanked 0 Times in 0 Posts
    So instead of this line:

    PHP Code:
    $result mysql_query($query
    or die (
    "Couldn't execute query."); 
    I have to put this?

    PHP Code:
    $row mysql_fetch_array($result); 
    $product $row['product']; 
    Cuz I don't need the mysql_query string if I have the mysql_fetch_array???

  • #6
    Regular Coder
    Join Date
    May 2006
    Posts
    106
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No, that was faulty selective quoting on my part. You still need the query to get the result. You need to fetch the data from the result so you need the fetch in addition to the query

  • #7
    Regular Coder
    Join Date
    Mar 2005
    Posts
    240
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Ah! I see... So in addition to the mysql_query string , I also have to have mysql_fetch_array.

    Let me give it a shot

  • #8
    Regular Coder
    Join Date
    Mar 2005
    Posts
    240
    Thanks
    1
    Thanked 0 Times in 0 Posts
    It worked !! Thanks

    Now let me ask this question... Is it "code friendly" to have so many <?php and ?> throughout this page?

    I figured it was the easiest way to bring back the values... coming from an HTML background, I found it easier to build the table first, then put in he <?php tags... rather than vice versa...

    Cuz I have about 20 or so fields that I would ask the customer to verify.

  • #9
    Regular Coder
    Join Date
    May 2006
    Posts
    106
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That question could start a flame war :-).

    I personally do both. Depends on the situtation and what seems best at the time. In this case I would probably add the html inside php tags and echo it out that way. No technical reason for doing it that way, just more readable and easier to sort thru with that many fields IMO.

  • #10
    Regular Coder
    Join Date
    Mar 2005
    Posts
    240
    Thanks
    1
    Thanked 0 Times in 0 Posts
    hahah... I figured..

    Since it's me that will be looking at the code only, I "see" better php inside HTML, so i'll code it that way...

    I just didn't know if there was a performance issue with the browser having to read 20 <?php tags rather than just one or 2


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •