Jump to content

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

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.