Jump to content

Check If Name Already Exists In The Column


Brandon_R

Recommended Posts

Hello members of this forum. I need some help with this mysql code. I made a submit script but i need to check if the entered "name" for example is already in the database. I already have a primary key for the ID but i dont want duplicate names also.

 

Also just a little question on the site - I already set the ID column to auto increment so if i want each new entry to have a ID + 1 from the last all i need to do is set the value it inserts into the id colum to ' '?

 

Thanks

Brandon_R

Hello members of this forum. I need some help with this mysql code. I made a submit script but i need to check if the entered "name" for example is already in the database. I already have a primary key for the ID but i dont want duplicate names also.

Just do a select query to see if a name already exists. If it does exist don't do the insert and return a error message.

SELECT * FROM users WHERE user_name="name_here"

 

 

Also just a little question on the site - I already set the ID column to auto increment so if i want each new entry to have a ID + 1 from the last all i need to do is set the value it inserts into the id colum to ' '?

Thanks

Brandon_R

When you do the insert query don't use the id as argument in values like so

INSERT INTO USERS(name)
VALUES("your_name_here")

The id will be inserted automatically

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.