php/mysql
I keep getting this error: \"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use n
The error is coming from this line:
if (!mysqli_query($dbCon,$sql)){
$sql
contains the result of
$dbCon->query($add_query);
Since that query was successful, $sql
contains TRUE
. mysqli_query()
requires the second argument to be a string, so TRUE
becomes "1"
, so you're effectively doing:
if (!mysqli_query($dbCon, "1")) {
That's not a valid query, so you get an error.
I think what you really meant to do was:
if (!$sql) {
die('Error: ' . $dbCon->error);
} else {
echo "dados atualizados!";
}
You don't need to keep calling mysqli_query()
repeatedly.
You should also learn to code using prepared statements instead of substituting variables into the query, to prevent SQL injection.