INSERT question
Moderator: General Moderators
- harrisonad
- Forum Contributor
- Posts: 288
- Joined: Fri Oct 15, 2004 4:58 am
- Location: Philippines
- Contact:
INSERT question
how can i insert a record into database if the record doesn't exist. I want to do this in a single query. Please give me a sample query. Thanks.
INSERT INTO `tablename` (`...`) VALUES ('...')
you'd better check the php manual
http://www.php.net/manual i think
you'd better check the php manual
http://www.php.net/manual i think
Last edited by AISBERG on Tue May 24, 2005 10:01 pm, edited 1 time in total.
*googles*
well, there's no IF NOT EXISTS kind of thing, but something like this might work:
well, there's no IF NOT EXISTS kind of thing, but something like this might work:
Code: Select all
INSERT INTO tb (firstname, lastname) VALUES ('Jack', 'Doe') ON DUPLICATE KEY UPDATE lastname = lastname;- harrisonad
- Forum Contributor
- Posts: 288
- Joined: Fri Oct 15, 2004 4:58 am
- Location: Philippines
- Contact:
I use this code but it gives mysql error:
Code: Select all
$query = "INSERT INTO directory (fname,lname) VALUES ('$fname','$lname') WHERE concat(fname,' ',lname)!='$fname $lname'";