View Full Version : $_SESSION to bring up a confirmation page

06-20-2006, 03:40 PM
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?


06-20-2006, 03:49 PM
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.

06-20-2006, 04:07 PM
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:


Then I have

$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:

<td align="right" width="230">
<p><?php echo $product ?></p>

So, when I look at this page, the "Product" field is blank... meaning for some reason it doesn't bring back the quiery

06-20-2006, 04:54 PM
Hi Cubsfan...

$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.

$row = mysql_fetch_array($result);
$product = $row['product'];

and then you can use the $product variable in your HTML.

06-20-2006, 04:57 PM
So instead of this line:

$result = mysql_query($query)
or die ("Couldn't execute query.");

I have to put this?

$row = mysql_fetch_array($result);
$product = $row['product'];

Cuz I don't need the mysql_query string if I have the mysql_fetch_array???

06-20-2006, 05:16 PM
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

06-20-2006, 07:44 PM
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

06-20-2006, 07:51 PM
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.

06-20-2006, 08:09 PM
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.

06-20-2006, 08:19 PM
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

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum