繁体   English   中英

更新表mysql&php

[英]UPDATE table mysql & php

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

您应该在一项声明中执行此操作。

$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'");

另外,您不应再使用PHP mysql_函数。 看一下更新,更快,功能更多的MySQLi

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM