gpt4 book ai didi

php - 更新时出现 SQL 错误

转载 作者:行者123 更新时间:2023-11-29 01:13:05 25 4
gpt4 key购买 nike

我遇到了一个错误,我不知道我的代码有什么问题。有人可以帮助我吗?

Error: UPDATE users SET voornaam = Test, achternaam = Test2, mail = test@test.com, tel = ,adres = , geslacht = man, bestuur = 0, tc = 0, ic = 0, jec = 0, rvr = , instructeur = 0, webmaster = 0 WHERE id = 1 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 'adres = , geslacht = man, bestuur = 0, tc = 0, ic = 0, jec = 0, rvr = , instruct' at line 1

$id = $_GET['u'];

$sql = "UPDATE users SET voornaam = $voornaam, achternaam = $achternaam,
mail = $mailadres, tel = $tel, adres = $adres, geslacht = $geslacht,
bestuur = $bestuur, tc = $tc, ic = $ic, jec = $jec, rvr = $rvr,
instructeur = $instructeur, webmaster = $webmaster WHERE id = ".$id."";

if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}

最佳答案

你应该有这样的东西:

$sql = "UPDATE `users` 
SET `voornaam` = '$voornaam',
`achternaam` = '$achternaam',
`mail` = '$mailadres',
`tel` = '$tel',
`adres` = '$adres',
`geslacht` = '$geslacht',
`bestuur` = '$bestuur',
`tc` = '$tc',
`ic` = '$ic',
`jec` = '$jec',
`rvr` = '$rvr',
`instructeur` = '$instructeur',
`webmaster` = '$webmaster'
WHERE id = '".$id."'";

这样,如果任何地方都有空白字段,您就会受到保护。您还应该确保清理所有要插入数据库的条目。

关于php - 更新时出现 SQL 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32976412/

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