Brandon_R Posted August 11, 2009 Share Posted August 11, 2009 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 Link to comment https://forums.phpfreaks.com/topic/169709-check-if-name-already-exists-in-the-column/ Share on other sites More sharing options...
RichardRotterdam Posted August 11, 2009 Share Posted August 11, 2009 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 Link to comment https://forums.phpfreaks.com/topic/169709-check-if-name-already-exists-in-the-column/#findComment-895479 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.