我有以下代码,更新分数和日期时可以正常工作。但是它不会更新该行的名称或国家。这是否与php字符串有关???很迷茫!

$userName = "John";
$userCountry = "USA";
$lowestScoreId =  99;
$userPoints = 500;


include 'config.php';


$currentTime = time();

mysql_query("UPDATE highScores SET name = $userName WHERE id='$lowestScoreId'");
mysql_query("UPDATE highScores SET score = $userPoints WHERE id='$lowestScoreId'");
mysql_query("UPDATE highScores SET country =$userCountry WHERE id='$lowestScoreId'");
mysql_query("UPDATE highScores SET date = $currentTime WHERE id='$lowestScoreId'");

最佳答案

您忘记了所设置值的引号。您可以在1个查询中执行此操作。

UPDATE highScores
SET `name`    = '$userName',
    `score`   = '$userPoints',
    `country` = '$userCountry',
    `date`    = '$currentTime'
WHERE id='$lowestScoreId'"

关于php - 更新表mysql&php,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11676479/

10-12 13:39