dropfaith Posted August 23, 2008 Share Posted August 23, 2008 Okay So what im trying to do inserts a record into database then i need to pull the id field back out and display it in the form of a link like below i know how to pull the id field of the inserted row but it wont display in the link like below any ideas? its for a business index where they enter the fileds for the business then it proceeds to a form to add the hours of the business <a href=addhours.php?Id=8> Quote Link to comment https://forums.phpfreaks.com/topic/121031-mysql_insert_id/ Share on other sites More sharing options...
Lamez Posted August 23, 2008 Share Posted August 23, 2008 oh this is simple <?php $id = $_POST['id']; $query = "INSERT INTO `table_name` (id) VALUES ('$id')"; mysql_query($query); $r = mysql_query("SELECT * FROM `table_name`"); $row = mysql_fetch_array($r); id = $row['id']; echo '<a href=addhours.php?Id='.$id.'>ID: '.$id.'</a>'; // 1 results while ($row = mysql_fetch_array($r)){ id = $row['id']; echo '<a href=addhours.php?Id='.$id.'>ID: '.$id.'</a><br>'; // ALL results } ?> Quote Link to comment https://forums.phpfreaks.com/topic/121031-mysql_insert_id/#findComment-623917 Share on other sites More sharing options...
JasonLewis Posted August 24, 2008 Share Posted August 24, 2008 Just use the mysql_insert_id() like you have in your topic title. echo "<a href='addhours.php?id=" . mysql_insert_id() . "'>" . mysql_insert_id() . "</a>"; Quote Link to comment https://forums.phpfreaks.com/topic/121031-mysql_insert_id/#findComment-624000 Share on other sites More sharing options...
Fadion Posted August 24, 2008 Share Posted August 24, 2008 Adding to ProjectFear's post, in the manual it is stated: Note: Because mysql_insert_id() acts on the last performed query, be sure to call mysql_insert_id() immediately after the query that generates the value. Meaning that you must call it before making any other queries after the insert one. Quote Link to comment https://forums.phpfreaks.com/topic/121031-mysql_insert_id/#findComment-624004 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.