WKoppel WKoppel - 7 months ago 9
SQL Question

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

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?

Console log from JS side

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


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

Answer

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