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 Quote 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. Quote 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 Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.