gpt4 book ai didi

php - 如何解决更新查询错误

转载 作者:行者123 更新时间:2023-11-29 07:28:02 26 4
gpt4 key购买 nike

我的错误是

Error while updating: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1

请记下拼写上没有错误,我检查了每一点后没有错误。更新查询导致了该错误。我尝试了很多次但没有解决。提前致谢。

<?php

include('db.php');
session_start();
if(isset($_POST['update']))
{
$fname = mysql_real_escape_string($_POST['fname'], $con1);
$lname = mysql_real_escape_string($_POST['lname'], $con1);
$phone = mysql_real_escape_string($_POST['phone'], $con1);
$zip = mysql_real_escape_string($_POST['zip'], $con1);
$city = mysql_real_escape_string($_POST['city'], $con1);
$country = mysql_real_escape_string($_POST['country'], $con1);
$userId = $_SESSION['userID'];

$strSQL = mysql_query("SELECT * FROM sarah_cloudRecord.user_info WHERE userId = '$userId'" , $con1);

//$Results = mysql_fetch_array($strSQL);
$numrows = mysql_num_rows($strSQL);

if($numrows != 0)
{

while ($row = mysql_fetch_assoc($strSQL))
{

$dblname = $row['lastName'];
$dbfname = $row['firstName'];
$dbphone = $row['phone'];
$dbzip = $row['zipCode'];
$dbcity = $row['city'];
$dbcountry = $row['country'];



if ($fname != $dbfname || $fname == $dbfname)
{
$newfName = $fname;
}

if ($lname != $dblname || $lname == $dblname)
{
$newlName = $lname;
}

if ($phone != $dbphone || $phone == $dbphone)
{
$newPhone = $phone;
}

if ($zip != $dbzip || $zip == $dbzip)
{
$newZip = $zip;
}

if ($city != $dbcity || $city == $dbcity)
{
$newCity = $city;
}

if ($country != $dbcountry || $country == $dbcountry)
{
$newCountry = $country;
}

}

$updateSQL = mysql_query("UPDATE sarah_cloudRecord.user_info SET firstName = '$newfName', lastName = '$newlName', phone = '$newPhone', city = '$newCity', zipCode = '$newZip', country = '$newCountry' WHERE userId = '$userId'", $con1);

if (mysql_query($updateSQL, $con1))
{
echo "Update Successfully!";
}
else {
echo "Error while updating: " . mysql_error($con1);
}

}

else {

echo "no records found";

}

}


else
{
?>

<script type="text/javascript">
window.location = "http://dev.metawarez.com/cloud/login.php";
</script>
<?php
}

?>

最佳答案

使用mysql_query两次。您将更新查询更改为

$updateSQL = "UPDATE sarah_cloudRecord.user_info SET firstName = '$newfName', lastName = '$newlName', phone = '$newPhone', city = '$newCity', zipCode = '$newZip', country = '$newCountry' WHERE userId = '$userId'";

if (mysql_query($updateSQL, $con1))

Note:- mysql is deprecated instead use mysqli or pdo

关于php - 如何解决更新查询错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33823696/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com