View Full Version : Quotes in mysql update

Jon W
03-04-2009, 03:35 AM
mysql_query("UPDATE notice SET notice=\"$notice\"") or die('Server Error: ' . mysql_error());

This query works fine when I put normal text, like "abcdefgjijklmnopqrstuvwxyx" and 12345678990" but when I use the quotes I get this error: Server 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 near '"This site is under construction.""' at line 1. And its because of the quotes. How do you get around this, how do I fix this?

Jon W

Old Pedant
03-04-2009, 03:55 AM
Use apostrophes.

mysql_query("UPDATE notice SET notice='$notice'")

If that causes problems becuz PHP doesn't allow substitution inside '...' then use string append instead of in place substitution. I'm not a PHP person, but I think you could do

mysql_query("UPDATE notice SET notice='" . $notice . "'")


03-04-2009, 06:09 AM
Go with-

mysql_query("UPDATE notice SET notice='$notice'");

This is the best practice. You might also consider encoding and decoding values-


This will avoid the problem entirely. Good luck.

Ranjit Viswakumar
Professional Services Specialist
HostMySite.com (http://hostmysite.com/?utm_source=bb)