gpt4 book ai didi

php - 更新 MySQL 错误但代码没有问题?

转载 作者:行者123 更新时间:2023-11-29 12:19:37 25 4
gpt4 key购买 nike

所以我得到这个错误:

更新记录时出现问题。 MySQL 错误:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在 'WHERE KittenID = '2'' 附近使用的正确语法

但是在我的代码中:

<?php
if(isset($_POST['Modify']))
{
$connection = mysql_connect("Deleted the login info");

// Check connection
if (!$connection)
{
echo "Connection failed: " . mysql_connect_error();
}
else
{
//select a database
$dbName="Katz";
$db_selected = mysql_select_db($dbName, $connection);

//confirm connection to database
if (!$db_selected)
{
die ('Can\'t use $dbName : ' . mysql_error());
}
else
{

$KittenID = $_POST["KittenID"];
$KittenAge = $_POST['KittenAge'];
$Name = $_POST['Name'];
$Email = $_POST['Email'];
$Gender = $_POST['Gender'];
$Personality = $_POST['Personality'];
$Activity = $_POST['Activity'];
$Comments = $_POST['Comments'];

$query = "UPDATE Kittenzz
SET KittenID = '$KittenID',
KittenAge = '$KittenAge',
Name = '$Name',
Email = '$Email',
Gender = '$Gender',
Personality = '$Personality',
Activity = '$Activity',
Comments = '$Comments',
WHERE KittenID = '$KittenID'";

$res = mysql_query($query);

if ($res)
{
echo "<p>Record Updated<p>";
}
else
{
echo "Problem updating record. MySQL Error: " . mysql_error();
}
}
}
mysql_close($connection);
}
?>

这没有任何意义,我已经读了这些代码行一个小时了,我看不出问题所在。它应该运行。谁能给我新的眼光吗?

最佳答案

删除'$comments'附近的逗号

 $query = "UPDATE Kittenzz 
SET KittenID = '$KittenID',
KittenAge = '$KittenAge',
Name = '$Name',
Email = '$Email',
Gender = '$Gender',
Personality = '$Personality',
Activity = '$Activity',
Comments = '$Comments'
WHERE KittenID = '$KittenID'";

关于php - 更新 MySQL 错误但代码没有问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29225260/

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