Jump to content

Duplicate ID


yandoo

Recommended Posts

Hi there,

 

I just run into a little problem and was hoping for a little advice.

 

I have a table in my database that has a INT AutoIncrement function as primary key ....

 

When i insert new records thought my php page i assign the Primary key of the Record by totaling the records currently and adding 1.

E.G:

<?php echo $totalRows_record +1 ?>

 

Heres the problem....

 

If i have say 10 records in the table and i delete record number 9 then when i try to INSERT another record i get error message DUPLICATE Primary Key! And thats because the query i am using is totaling the number of records i.e. 9 (after deleting record 9)....

 

How can I overcome this please???

 

Thanks :)

Link to comment
Share on other sites

leave the auto-incremented value alone.  Let MySQL take care of assigning the value. The record number of any record is immaterial. If you want to display records with sequential (but meaningless) numbers, just use a counter ...

Link to comment
Share on other sites

Hi there,

 

How do i assign a value to the primary key? In phphmyadmin itl ets me insert a record without putting in a primary key value...

 

But how would i do it in php????? Normally i have to have a value in hidden field as priamry key..??

 

Thanks :)

Link to comment
Share on other sites

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.