Jump to content

Archived

This topic is now archived and is closed to further replies.

yarub

Error in SQL Syntax

Recommended Posts

I made a really simple shoutbox, and I'm getting an error when apostrophes, quotation marks, and other php-recognized characters are used.

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 't know anything.'

What was typed was: I don't know anything.

How can I allow those characters? Here's what I'm using to input it:

[code]$add_info = "insert into shoutbox values ('', '$user', '$date', '$ip', '$_POST[content]', '1')";
mysql_query($add_info,$conn) or die(mysql_error());[/code]
Content is the field it's erroring. Help please.

._.

Share this post


Link to post
Share on other sites
You can either escape them with a backslash, or use their HTML entity instead.

[code]INSERT INTO `table` (`id`,`something`) VALUES ('1','There\'s a hole in my pocket')[/code]
[code]INSERT INTO `table` (`id`,`something`) VALUES ('1','There&#39:s a hole in my pocket')[/code]
{Replace the colon with a semi-colon in &#39:)

Share this post


Link to post
Share on other sites
Is there a way to do that automatically? Like, when they submit their response, can I have my script change them automatically? I'm sure 99.9% of my users don't know ISO entities. >_<;

Share this post


Link to post
Share on other sites
You can convert to entities with htmlentities() or you can escape the quotes with str_replace()

Share this post


Link to post
Share on other sites
Oh. I knew that too. Haha. Thanks a lot for your help.

Share this post


Link to post
Share on other sites
[!--quoteo(post=385414:date=Jun 18 2006, 09:22 PM:name=yarub)--][div class=\'quotetop\']QUOTE(yarub @ Jun 18 2006, 09:22 PM) [snapback]385414[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Oh. I knew that too. Haha. Thanks a lot for your help.
[/quote]
No problem [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.