I am trying to update my SQL table with the help of this php code:
$description = "Something about myself";
$insert = $con->prepare("INSERT INTO kys_write (Author, writing , Title , Description , Assets) VALUES (?,?,?,?,?)");
$insert->bind_param("ssssi",$author,$data,$title,$description, $ImageExist);
$insert->execute();
$statement = $con->prepare("SELECT id FROM kys_write WHERE Title=?");
$statement->bind_param("s",$title);
$statement->execute();
$statement->bind_result($lastId);
//Everything works fine if this whole part is removed
$sql = "UPDATE kys_essentials SET LastId=".$lastId;
if ($con->query($sql) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $con->error;
}
I am getting a error:
Error updating records:Commands out of sync, you cannot run this command now.
What causes this, and how can I avoid it?