gpt4 book ai didi

php - 无法更新 MySQL 表

转载 作者:行者123 更新时间:2023-12-01 00:14:16 26 4
gpt4 key购买 nike

我不知道我做错了什么,但我的小更新代码给我一条错误消息,我不知道如何解决它。

这是我的代码:

<?php

include('dbconfig.php');
$con = mysql_connect($host, $username, $password) or die(mysql_error()) ;

if (!$con){
die('Could not connect: ' . mysql_error());
}
mysql_select_db($db, $con);

function sqlEscape($string){
return "'".mysql_real_escape_string($string)."'";
}

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


$q = "UPDATE records SET `name` = " + sqlEscape($_POST['name']) + ",
`age` = " + sqlEscape($_POST['age']) + ",
`location` = " + sqlEscape($_POST['location']) + ",
`telephone` = " + sqlEscape($_POST['telephone']) + "

WHERE id = $_POST[id]";

mysql_query($q) or die(mysql_error());

}
?>

这是它打印出来的错误信息:

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' at line 1

有人能看出我哪里出错了吗?

感谢您的帮助。

最佳答案

您正在使用 + 运算符添加字符串,该运算符用于添加数字。在 PHP 中,字符串与 .(句点)运算符连接。

$q = "UPDATE records SET `name` = " . sqlEscape(...) . ",

等等

关于php - 无法更新 MySQL 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8597497/

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