0

我有以下代码,它在更新分数和日期时工作正常。但它不会更新行的名称或国家。这与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'");
4

3 回答 3

11

您忘记了您设置的值周围的引号。您可以在 1 个查询中做到这一点。

UPDATE highScores
SET `name`    = '$userName',
    `score`   = '$userPoints',
    `country` = '$userCountry',
    `date`    = '$currentTime'
WHERE id='$lowestScoreId'"
于 2012-07-26T19:17:39.760 回答
1

您应该在一份声明中做到这一点。

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

include 'config.php';

$currentTime = time();

mysql_query("UPDATE highScores SET name = '$userName', score = '$userPoints', country = '$userCountry', date = '$currentTime' WHERE id='$lowestScoreId'");
于 2012-07-26T19:20:09.413 回答
1

此外,您不应再使用 PHP mysql_ 函数。看看MySQLi,它更新、更快、功能更多。

于 2012-07-26T19:34:43.013 回答