mysql – UPDATE LIMIT statement in PHP causes syntax error-ThrowExceptions

Exception or error:
$query1 = "update rooms set available='1' where typeId='$typeId' order by roomId limit='$room'"; 

I am getting syntax error near near ‘=’1” but I can’t find the error. I’m pretty sure it’s written correctly.

How to solve:

LIMIT can’t assign values, remove the quotes. Change it to:

$query1 = "update rooms set available='1' where typeId='$typeId' order by roomId limit $room";

Answer:

In SQL, LIMIT can not be assigned and you can’t use quotes around the limit number, so use this:

 $query1 = "update rooms set available = '1' where typeId = '$typeId' order by roomId limit $room ";

Don’t use '$room'.

Answer:

Just change your query to this:

$query1 = "update `rooms` set available='1' where typeId='$typeId' order by roomId limit '$room'"; 

Leave a Reply

Your email address will not be published. Required fields are marked *