gpt4 book ai didi

PHP+MySQL UPDATE 查询(多列)不起作用

转载 作者:行者123 更新时间:2023-11-29 13:43:54 24 4
gpt4 key购买 nike

好吧,这可能是我忽略的简单事情,但我已经对此进行了很多次梳理..!

只需通过 PHP 表单进行简单更新,引入变量,构建查询:

// Connect
$connect = mysql_connect('host','login','passwd');
if (!$connect) { $errors .= "Not connected : ".mysql_error(); }
$database = mysql_select_db('db', $connect);
if (!$database) { $errors .= "Could not get to that database: ".mysql_error(); }

// Update database table
$info = "UPDATE `gsa_officers` SET `term` = '2012-2013', `office` = 'President', `type` = 'Poop', `dept` = 'Visual Arts', `name` = 'Matthew W. Jarvis', `email` = 'president@gsa.ucsd.edu', `blurb` = 'Serves as Chair of both the GSA Executive Committee and Council, oversees the direction of the organization and ensures the execution of its responsibilities and commitments.', `picture` = 'http://gsa.ucsd.edu/sites/gsa.ucsd.edu/files/mat%20w%20jarvis.jpg' WHERE `id` = 1";
$query = mysqli_query($info);
if (!$query) { $errors .= "Bad query: ".mysql_error(); }
mysql_close($connect);

我没有收到任何错误,它只打印出:“错误查询:”

我错过了什么/做错了什么?任何额外的眼球都将受到赞赏 ^_^

最佳答案

您正在使用mysql_connect()连接到数据库服务器并选择数据库。然后使用 mysqli_query() 运行查询,然后使用 mysql_error() 报告错误。您不能混合使用这些 API。

您应该始终使用 mysqli_* 函数,因为 mysql_* 函数已弃用,并将从 PHP 的 future 版本中删除。

示例:

// Connect
$mysqli = new mysqli('host','login','passwd','db');
if ($mysqli->connect_error) { $errors .= "Not connected : ".$mysqli->connect_error; }

// Update database table
$info = "UPDATE `gsa_officers` SET `term` = '2012-2013', `office` = 'President',
`type` = 'Poop', `dept` = 'Visual Arts', `name` = 'Matthew W. Jarvis',
`email` = 'president@gsa.ucsd.edu',
`blurb` = 'Serves as Chair of both the GSA Executive Committee and Council, oversees the direction of the organization and ensures the execution of its responsibilities and commitments.',
`picture` = 'http://gsa.ucsd.edu/sites/gsa.ucsd.edu/files/mat%20w%20jarvis.jpg'
WHERE `id` = 1";
if (!$mysqli->query($info)) {
$errors .= "Bad query: ".$mysqli->error;
}
$mysqli->close();

关于PHP+MySQL UPDATE 查询(多列)不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17711523/

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