Error updating record: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '? WHERE user_id <> ? AND 1 = 1' at line 1
Here is my code:
<?php
$dbhost = "localhost";
$dbuser = "*******";
$dbpass = "********";
$dbname = "************";
$conn = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
$newcredit = $_POST["newLOC"];
$UID = 1;
if(! $conn ) {
die('Could not connect: ' . mysqli_error());
}
//echo 'Connected successfully<br>';
$sql = 'UPDATE users SET line_of_credit = ? WHERE user_id <> ? AND 1 = 1';
$stmt = $conn->prepare($sql);
$stmt->bind_param('ii', $newcredit, $UID);
$stmt->execute();
if (mysqli_query($conn, $sql)) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . mysqli_error($conn);
}
mysqli_close($conn);
?>
<?php
}
?>
The thing is, it IS updating the table, so I'm not sure why I'm getting the error message. When I run the code with values in the database itself, it runs fine.