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
https://forums.phpfreaks.com/topic/81724-insert-with-a-check/
Share on other sites

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.