gpt4 book ai didi

php - 网页中的 MySQL UPDATE 查询错误

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

我的更新查询失败,尽管语法对我来说看起来很好(我有另一个更新查询在同一页面上运行良好)。

mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("sitename") or die(mysql_error());

$id = $_GET['id'];

if (isset($_POST['submit'])){

$b = mysql_real_escape_string(trim($_POST['body']));

//**You have an error in your SQL syntax;** --> ?
mysql_query ("UPDATE body SET body= $b WHERE id = $id") or die (mysql_error() );

// $b is fine
echo "$b";

}

如何呈现 HTML 审核表单..

// Puts SQL Data into an array
$q = mysql_query("SELECT * FROM vote") or die (mysql_error());

// Now we loop through the database
echo "<br />";
while ($ratings = mysql_fetch_array($q))
{
//This outputs the doctors's name
echo "Doctor's name:" . $ratings['doctor_name'] ."<br />";

//This outputs a textarea for the user to submit comments
echo "<b>Your Experience: </b>";
echo "<form method='post' action='review_doctors.php'>

<textarea name='body'></textarea>
<input type='submit' name='submit' value='Send' id='submit'/>
</form>
";
echo "<br />";

echo "<p> </p>";
}

为什么每当提交评论时我都会收到 SQL 语法错误?

最佳答案

因此,您正在从 $_GET 数组中设置 $id ,该数组可能不会在通过帖子提交表单时设置。

您正在运行的更新查询位于 POST 检查中(检查是否设置了 $_POST['submit'])。

您可能想要发送帖子正文中的 $id 值并将其从帖子数组中提取。

关于php - 网页中的 MySQL UPDATE 查询错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26853744/

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