Jump to content


Photo

Error in SQL Syntax


  • Please log in to reply
5 replies to this topic

#1 yarub

yarub
  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts
  • LocationSioux City, IA

Posted 18 June 2006 - 08:02 PM

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:

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

._.

#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 18 June 2006 - 08:05 PM

You can either escape them with a backslash, or use their HTML entity instead.

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

#3 yarub

yarub
  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts
  • LocationSioux City, IA

Posted 18 June 2006 - 08:16 PM

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. >_<;

#4 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 18 June 2006 - 08:21 PM

You can convert to entities with htmlentities() or you can escape the quotes with str_replace()

#5 yarub

yarub
  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts
  • LocationSioux City, IA

Posted 18 June 2006 - 08:22 PM

Oh. I knew that too. Haha. Thanks a lot for your help.

#6 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 18 June 2006 - 08:31 PM

[!--quoteo(post=385414:date=Jun 18 2006, 09:22 PM:name=yarub)--][div class=\'quotetop\']QUOTE(yarub @ Jun 18 2006, 09:22 PM) View Post[/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\" /]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users