refiking Posted June 7, 2007 Share Posted June 7, 2007 I am trying to use the auto increment feature and I am completely stuck. I am trying to automatically give each form a new record number. What am I missing? Here is the code: $query1 = "SELECT last_insert_id(record_id) FROM Records"; $record1 = mysql_query($query1); $record_id = $record1 + 1; Quote Link to comment https://forums.phpfreaks.com/topic/54517-auto-increment-help-needed/ Share on other sites More sharing options...
Yesideez Posted June 7, 2007 Share Posted June 7, 2007 If you use mysql_isert_id() immediately after inserting a record you'll get the last index number of the record added. mysql_query("INSERT INTO `table` (`name`) VALUES ('".$name."')"); $recordid=mysql_insert_id(); $recordid would then represent the last entry. If you've not inserted a record and want to get the last record number you can use this: $fetch=mysql_fetch_assoc(mysql_query("SELECT `recordid` FROM `table` ORDER BY `recordid` DESC LIMIT 1")); $lastrecordid=$fetch['recordid']; EDIT: corrected spelling of "SELCT" to "SELECT" - typo! Quote Link to comment https://forums.phpfreaks.com/topic/54517-auto-increment-help-needed/#findComment-269634 Share on other sites More sharing options...
Yesideez Posted June 7, 2007 Share Posted June 7, 2007 Did my answer to your last question work? EDIT: I can see you've got another error message - not to worry! Quote Link to comment https://forums.phpfreaks.com/topic/54517-auto-increment-help-needed/#findComment-269636 Share on other sites More sharing options...
refiking Posted June 7, 2007 Author Share Posted June 7, 2007 The following error message appears: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/ctpwebco/public_html/leads/proc.php on line 60 Here is the code for line 60: $fetch = mysql_fetch_assoc(mysql_query("SELCT `record_id` FROM `Records` ORDER BY `record_id` DESC LIMIT 1")); Neither problem is fixed, yet? Did I miss a step or is there something else to it? Quote Link to comment https://forums.phpfreaks.com/topic/54517-auto-increment-help-needed/#findComment-269638 Share on other sites More sharing options...
refiking Posted June 7, 2007 Author Share Posted June 7, 2007 Problem Solved! Thanks a million!!! Now, I can thank you 2 million if you can help me with the other one. Quote Link to comment https://forums.phpfreaks.com/topic/54517-auto-increment-help-needed/#findComment-269641 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.