3

How do i do this. Here is my code`

$insert = "REPLACE INTO drinks SET
name='".$name2."', category=' ".$category2." ', date=CURDATE()";
if (@mysql_query($insert)) {
echo '<h4 class="alert_info">Drinks added</h4>';
} else {
echo 'Error adding event: ' .
mysql_error() . '';
}
4

1 回答 1

5

Generally, what you are looking for is called "upsert" (ie UPdate or inSERT). From this link apparently for MySQL the syntax is:

INSERT ... ON DUPLICATE KEY UPDATE

With more info from the MySql manual.

于 2013-03-31T23:44:11.553 回答