Jump to content

Insert with a check


SirChick

Recommended Posts

Is there a way to have an insert with a check rather than doing a select query to check first? I'm trying to cut down the amount of queries i got so was hoping it was possible.. .the idea is to insert only if the data is not already existing in the database.. so i thought perhaps an INSERT can use the WHERE clause to check for uniqueness?

 

This is what i got:

 

$InsetIP = mysql_query("INSERT INTO iplogs (UserID, IP)
			VALUES ('{$_SESSION['Current_User']}', '$ip')")
			or die(mysql_error());

 

Then i wanted to add something like WHERE $ip does not already exist for this UserID.

 

Can it be done in one INSERT or will it require a select query first?

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.