Forum Moderators: coopster

Message Too Old, No Replies

mySQL auto-increment id column

using phpMyAdmin, need to know how to set up a unique id

         

amdorsey

8:13 pm on Mar 30, 2004 (gmt 0)

10+ Year Member



need to set-up a mySQL database with a unique id, so I can have an update section.

I have a site with a "events" page (a list of events, date, event name and event description) I have a form with 3 fields (date, name and description)...

I need to do 4 things...
insert records (not a problem)
display records (not a problem)
update records (can't figure how to update, need id)

Any Help?

aus_dave

10:11 pm on Mar 30, 2004 (gmt 0)

10+ Year Member



That's only 3 things above...:)

To update is similar to displaying records. Get the data from the database, but display the information in a form (echo the data in the appropriate form field like a text box, radio button etc.). Then have an update button that posts the edited variables for that record to your update MySQL query.

You should have an 'eventID' field in your database, and track that through the form with a hidden field if you don't want to display it.

jetboy_70

11:19 pm on Mar 30, 2004 (gmt 0)

10+ Year Member



In PHP MyAdmin:

Insert a new field into mytable.

Give it a name such as 'mytableid'.
Set 'Type' to 'INT'.
Set 'Attributes' to 'UNSIGNED'.
Set 'Extra' to 'auto_increment'.
Select 'Primary'.

Now if you insert a record into mytable, mytableid will automatically contain a unique record ID.