gpt4 book ai didi

php - SQL 表未在 PHP 中更新

转载 作者:太空宇宙 更新时间:2023-11-03 12:32:01 24 4
gpt4 key购买 nike

我正在尝试在 PHP 中创建一个更新函数,但记录似乎没有根据更新进行更改。我创建了一个 JSON 对象来保存传递给该文件的值,并且根据我运行的 Firebug Lite 控制台,这些值输出得很好,所以 sql 端可能有问题。谁能发现问题?非常感谢您的帮助!

<?php

$var1 = $_REQUEST['action']; // We dont need action for this tutorial, but in a complex code you need a way to determine ajax action nature
$jsonObject = json_decode($_REQUEST['outputJSON']); // Decode JSON object into readable PHP object

$name = $jsonObject->{'name'}; // Get name from object
$desc = $jsonObject->{'desc'}; // Get desc from object
$did = $jsonObject->{'did'};// Get id object


mysql_connect("localhost","root",""); // Conect to mysql, first parameter is location, second is mysql username and a third one is a mysql password
@mysql_select_db("findadeal") or die( "Unable to select database"); // Connect to database called test


$query = "UPDATE deal SET dname = {'$name'}, desc={'$desc'} WHERE dealid = {'$did'}";
$add = mysql_query($query);
$num = mysql_num_rows($add);

if($num != 0) {

echo "true";

} else {

echo "false";

}

?>

最佳答案

我相信你误用了大括号。单引号应该放在它们的外面。:

"UPDATE deal SET dname = {'$name'}, desc={'$desc'} WHERE dealid = {'$did'}"

成为

"UPDATE deal SET dname = '{$name}', desc='{$desc}' WHERE dealid = '{$did}'"

附带说明一下,使用任何 mysql_* 函数在安全方面都不是很好。我建议查看 php 的 mysqlipdo扩展名。

关于php - SQL 表未在 PHP 中更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14964342/

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