tags:

views:

47

answers:

3

I am inserting some info into a database table with php and mysql. I am trying to diplay the same information inserted into the table in the next page.

I know that if I send the ID it won't work becuase the row hasn't been created yet, it will display an empty page. Is there a way around this? I need the information to come from the table.

+2  A: 

Edit: If the row hasn't been created yet, it can't be returned by the DB. Therefore, you are trying to access a given page in 2 different ways.

You can do something like the following:

$object = null;
if (isset($_REQUEST['id'])) {
    //call the DB to access the record data and put it 
    //into the $object that's representing that table.
}
else if (isset($_SESSION['data to display'])) {
    //retrieve that data and set the values on $object
    //then...
    unset($_SESSION['data to display']);
}
else {
    // bad input data. either call die() with an error message, 
    //or redirect to an error page, or do whatever else you might 
    //want to do.
}

From here on, everything should be common functionality for building the actual page.

Zack
I think he hasn't created the row yet...
MiseryIndex
That is exactly my problem. The row hasn't been created yet. so how to I call that row in the next page?
francesco
Thank you Zack, will work around this.
francesco
+1  A: 

I'm confused by your question, as it makes it sounds like you are creating the record, then going to the next page, so why wouldn't be there?

otherwise, you could just throw it into $_SESSION.

GSto
The Id of the new row, not yet created, is sent with the link to the next page. Because it hasn't been created yet when the link goes to the next page it is empty.
francesco
+1  A: 

I think mysql_insert_id will get you where you need to go. Insert the record, then call that and redirect the user to that id/ page.

Tom