I'm attempting to UPDATE a table and it displays an SQL syntax error but it properly updates the table. I'm not really sure what the reasoning is behind it and I just don't want to turn off the error completely.
Error: 1
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1
This is the function:
function logTime($time){
$sql1 = mysqli_query($this->con, "UPDATE `pilots` SET `active`='0',`total_time`='".$time."' WHERE username = '".$this->whoMe()."'");
if (mysqli_query($this->con, $sql1)) {
header('Location: index.php?pausedtime');
die();
}
else {
echo "Error: " . $sql1 . "<br>" . mysqli_error($this->con);
}
}
That's because you're using mysqli_query()
twice... $sql1
line should be enough. Try this:
function logTime($time){
$sql1 = mysqli_query($this->con, "UPDATE `pilots` SET `active`='0',`total_time`='".$time."' WHERE username = '".$this->whoMe()."'");
if($sql1){
header('Location: index.php?pausedtime');
die();
} else {
echo "Error: " . $sql1 . "<br>" . mysqli_error($this->con);
}
}
Also note, that such queries should be executed with prepared statements for security reasons (at least).