Eiolon Posted December 23, 2009 Share Posted December 23, 2009 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; } } Quote Link to comment Share on other sites More sharing options...
p2grace Posted December 23, 2009 Share Posted December 23, 2009 First, to get the last insert id, just execute the following: $id = mysql_insert_id(); That will return the id of the last insert statement performed. Then to redirect just do the following: header("Location: company.php?id=$id"); Quote Link to comment Share on other sites More sharing options...
Eiolon Posted December 23, 2009 Author Share Posted December 23, 2009 Thanks, but the value is still not being passed to company.php. In the address bar it is showing: http://localhost/contacts/company.php?id=$id Instead of: http://localhost/contacts/company.php?id=1 Quote Link to comment Share on other sites More sharing options...
p2grace Posted December 23, 2009 Share Posted December 23, 2009 If it's in double-quotes it'll pass the value of the variable, not the variable itself. If its in single quotes, it'll only pass the variable string. Make sure it's in double quotes. Quote Link to comment Share on other sites More sharing options...
Eiolon Posted December 23, 2009 Author Share Posted December 23, 2009 Oh, thanks very much Working! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.