PHP/MySQL says success when updating an record, but no changes in table [duplicate]

时间:2023-01-25 11:24:56

This question already has an answer here:

这个问题在这里已有答案:

Really simple question which I can't figure out. Code to update table :

非常简单的问题,我无法弄清楚。代码更新表:

$loc = $_POST['sql_id'];
$link = $_POST['link'];
$sql_c = $_POST['name_c'];
$val = $_POST['val'];
$query = "UPDATE $link SET $sql_c='$val' WHERE id='$loc' ";

if ($conn->query($query) === TRUE) {
echo "Success!";
} else {
    echo "Error: " . $conn->error;
}

It returns Success!, but there are no changes in the table. What am I missing here?

它返回Success!,但表中没有变化。我在这里想念的是什么?

Console log from JS side

JS方面的控制台日志

 (
    [id] => 2
    [link] => Test123
    [name_c] => i1
    [val] => Texx
)

Table name is Test123 with columns id,paid,i1,i2,i3,i4,i5

表名是Test123,列id,付费,i1,i2,i3,i4,i5

2 个解决方案

#1


1  

It should be $_POST['id']; not $_POST['sql_id']; according to your code.

它应该是$ _POST ['id'];不是$ _POST ['sql_id'];根据你的代码。

#2


0  

The $conn->query() method returns an object if success or FALSE if an error occurred. Could you paste the result of your $conn->query() call?

$ conn-> query()方法在成功时返回一个对象,如果发生错误则返回FALSE。你能粘贴$ conn-> query()调用的结果吗?

So if your query is $result_l = $conn->query("UPDATE event SET length='$i_c' WHERE id='$id' "); just do a var_dump($result_l); and post it here.

因此,如果您的查询是$ result_l = $ conn-> query(“UPDATE event SET length ='$ i_c'WHERE id ='$ id'”);只需做一个var_dump($ result_l);并在此发布。

#1


1  

It should be $_POST['id']; not $_POST['sql_id']; according to your code.

它应该是$ _POST ['id'];不是$ _POST ['sql_id'];根据你的代码。

#2


0  

The $conn->query() method returns an object if success or FALSE if an error occurred. Could you paste the result of your $conn->query() call?

$ conn-> query()方法在成功时返回一个对象,如果发生错误则返回FALSE。你能粘贴$ conn-> query()调用的结果吗?

So if your query is $result_l = $conn->query("UPDATE event SET length='$i_c' WHERE id='$id' "); just do a var_dump($result_l); and post it here.

因此,如果您的查询是$ result_l = $ conn-> query(“UPDATE event SET length ='$ i_c'WHERE id ='$ id'”);只需做一个var_dump($ result_l);并在此发布。