gpt4 book ai didi

php - SQL 语法错误 id 突然为零

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

有人知道这里可能出了什么问题吗?

<?php
$q = intval($_GET['q']);
echo $q." "; // $q=2
$d = $_GET['d'];
echo $d." "; //$d=3priority
$m = preg_replace('/[0-9]+/', '', $d);
echo $m." "; //$m = priority
$s = intval($_GET['d']);
echo $s;// $s = 3
$sql = "UPDATE form SET $m = $q WHERE id = $s";
$result = $conn->query($sql);
if ($conn->query($sql) === TRUE) {echo "das";}
else{
echo "Error: " . $sql . "<br>" . $conn->error;
}
?>

我收到错误消息:

UPDATE form SET = 0 WHERE id = 0 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 '= 0 WHERE id = 0' at line 1

但是,如果我回显 $m/$q/$s/$d 你会显示正确的值。但不知何故,它们在sql语句中被更改为0。

如果你能帮助我,那就太好了:)

最佳答案

试试这个

$sql = "UPDATE form SET" . $m . "=" . $q . " WHERE id =" . $s;

关于php - SQL 语法错误 id 突然为零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41847714/

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