Jump to content

Recommended Posts

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;

Link to comment
https://forums.phpfreaks.com/topic/54517-auto-increment-help-needed/
Share on other sites

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!

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.