简体   繁体   中英

unable to update value in mysql database using php

I am not able to update MySQL table using PHP. How can I do that?

I have tried by changing the order of double quotes.

$name=mysql_real_escape_string($_POST["steel"]);
$db->execute("UPDATE order SET need=$name WHERE raw-id='1'");

It should store $name in the database.

您应将$ name用单引号引起来,因为您正在尝试将字符串传递到SQL中

$db->execute("UPDATE order SET need='$name' WHERE `raw-id`='1'");

您需要将列名包装在反引号中,因为其中包含破折号,例如:

$db->execute("UPDATE order SET need = '$name' WHERE `raw-id` = 1");

By referring to the manual I think you should first prepare your query and then use execute() method. Something like this:

$query = "INSERT INTO myCity (Name, CountryCode, District) VALUES (?,?,?)";
$stmt = $mysqli->prepare($query);
$stmt->execute();

您应该用单引号和括号将{$name}括起来,因为需要行是SQL中的字符串

$db->execute("UPDATE order SET need='{$name}' WHERE `raw-id`='1'");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM