happs Posted October 13, 2007 Share Posted October 13, 2007 Hey peeps Hoping you can help.. function add_league () { $name = strtoupper(trim(addslashes($_POST['name']))); mysql_query("INSERT INTO leagues (name, format, division) VALUES ('{$name}', '{$_POST['format']}', 'A')"); echo 'League Added: ' . $name . '(' . $_POST['format'] . ')'; echo ' [ <a href="' . $_SERVER['PHP_SELF'] . '?action=edit&league_id=' . $row_leagues['id'] . '">EDIT THIS LEAGUE</a> ]'; } As you can see, an entry has just been made into the database, but the following echo requires that entrie's ID. What is the best way of getting the LAST entry into the database ? Or even better, get THAT entrie's ID. Thank you very much for your help in advance. - Alex Link to comment https://forums.phpfreaks.com/topic/73108-solved-finding-next-index-in-table/ Share on other sites More sharing options...
marcus Posted October 13, 2007 Share Posted October 13, 2007 mysql_insert_id() Usage: $sql = "INSERT INTO `table` ...etc"; $res = mysql_query($sql) or die(mysql_error()); $last_id = mysql_insert_id(); It corresponds with the LAST SQL Query executions. Link to comment https://forums.phpfreaks.com/topic/73108-solved-finding-next-index-in-table/#findComment-368707 Share on other sites More sharing options...
happs Posted October 13, 2007 Author Share Posted October 13, 2007 That's fantastic. Thank you Link to comment https://forums.phpfreaks.com/topic/73108-solved-finding-next-index-in-table/#findComment-368723 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.