Jump to content

Last insert ID and redirect


Eiolon

Recommended Posts

I am trying to make it so when a record is created the user will be redirected to that record once submitted.

 

It is redirecting to the proper page but it is not pulling up the record.  I'm not sure how to get the $id to pass through using the header('Location') redirect.

 

if (empty($errors)) {

$insert = "INSERT INTO companies (name, phone1, phone2, fax, website, customer, contract) VALUES ('$n','$p1','$p2','$f','$w','$cu','$co')";
$result = mysql_query($insert) OR die ('Could not add the company to the database.');

$id = mysql_result((mysql_query("SELECT * FROM companies WHERE id = '$id'")), 0, 'id');

if ($insert) {
header('Location: company.php?id=".$id."');
exit; }

}

Link to comment
https://forums.phpfreaks.com/topic/186169-last-insert-id-and-redirect/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.