无法使用php更新mysql表

时间:2015-03-20 05:48:07

标签: php mysql

<?php
$dbhost = 'localhost';
$dbuser = 'santhosh';
$dbpass = 'Santhu';
$database = 'car';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($database, $conn);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
$name="nair";
$lat="123";
$lon="456";
$sql = "UPDATE cart SET latitude='$lat',longitude='$lon' WHERE uname<="$name";
if (mysql_query($sql)) {
echo "New record updated successfully";
} else {
echo "Error: " ;
}
mysql_close($conn);
?>

我收到消息&#34;错误&#34;这意味着我无法更新我的表格。请告诉我我的代码中有什么错误...先谢谢你

5 个答案:

答案 0 :(得分:0)

请更改您的查询,如下所示。

"UPDATE cart SET latitude='$lat',longitude='$lon' WHERE uname = '".$name."'";

我希望这会对你有所帮助

答案 1 :(得分:0)

我认为查询会像这样

  $sql = "UPDATE `cart` SET `latitude`='".$lat."',`longitude`='".$lon."' WHERE `uname`='".$name."'"; 

答案 2 :(得分:0)

<?php
$dbhost = 'localhost';
$dbuser = 'santhosh';
$dbpass = 'Santhu';
$database = 'car';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($database, $conn);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
$name="nair";
$lat="123";
$lon="456";
$sql = "UPDATE cart SET latitude='$lat',longitude='$lon' WHERE uname='$name'";
if (mysql_query($sql)) {
echo "New record updated successfully";
} else {
echo "Error: " ;
}
mysql_close($conn);
?>

答案 3 :(得分:0)

您的查询中有一个错误引用的错误。

"UPDATE cart SET latitude='$lat',longitude='$lon' WHERE uname<=$name";
                                                             ^^^^^^^^

更新了查询

"UPDATE cart SET latitude = '$lat',longitude = '$lon' WHERE uname = '".$name."'";
                                                                  ^^^^^^^^^^^^^^

答案 4 :(得分:0)

$sql = "UPDATE cart SET latitude = '$lat',longitude='$lon' WHERE uname = '".$name."'";

这段代码解决了我的问题。 谢谢大家的答案......