I try to update my table but I give this error please help me
function updatePost($id , $title, $content, $date, $groups)
{
$connection = mysqli_connect(DataBaseManager::HOST, DataBaseManager::USER, DataBaseManager::PASSWORD, DataBaseManager::DATABASENAME);
$sqlCommand = "UPDATE posts
SET title = '$title', content = '$content', date = '$date' , groups = '$groups'
WHERE id == 1";
if ($connection->query($sqlCommand) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $connection->error;
}
$connection->close();
}
Your where
clause has 2 equal signs. Change it to a single equal sign ... also, date is a reserved word so you'll need to wrap it in backticks.
$sqlCommand = "UPDATE posts
SET title = '$title' ,
content = '$content',
`date` = '$date' ,
groups = '$groups'
WHERE id = 1";
You need to treat your SQL query like a string and concat your variables accordingly:
"UPDATE posts SET title = '".$title."', content = '".$content."', date = '".$date."' , likes = '".$likes."', groups = '".$groups."' WHERE id = '".$id."'";