I'm new to MySQL. Whats wrong with this code? It doesn't update data.
"INSERT INTO highscores (name, score, maila, ip)" . "VALUES ('$name', '$score', '$maila', '$ip')" .
"ON DUPLICATE KEY UPDATE score;" . "UPDATE highscores SET (if score>'$score') {score=$score} WHERE name=$name"
This works:
"INSERT INTO highscores (name, score, maila, ip) ".
"VALUES ('$name', '$score', '$maila', '$ip') " . "
on duplicate key update score = greatest开发者_开发技巧(score, $score)"
Thanks to binaryLV: MSQL: How to overwrite entry only if new one is higher? else create new entry
When you use ON DUPLICATE KEY UPDATE
, you must also specify what to update, that is, in PHP, the right query would be:
$q = "INSERT INTO highscores (name, score, maila, ip) ".
"VALUES ('$name', '$score', '$maila', '$ip') ".
"ON DUPLICATE KEY UPDATE score='$score'";
精彩评论