开发者

Why doesn't this statement update the data in MySQL?

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'";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜