frapet
frapet

Reputation: 229

php passing Id to next page and from database

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.

Upvotes: 1

Views: 910

Answers (3)

Zack Marrapese
Zack Marrapese

Reputation: 12080

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.

Upvotes: 2

Tom
Tom

Reputation: 22831

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.

Upvotes: 1

GSto
GSto

Reputation: 42350

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.

Upvotes: 1

Related Questions