yarub Posted June 18, 2006 Share Posted June 18, 2006 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.._. Link to comment https://forums.phpfreaks.com/topic/12322-error-in-sql-syntax/ Share on other sites More sharing options...
zq29 Posted June 18, 2006 Share Posted June 18, 2006 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':s a hole in my pocket')[/code]{Replace the colon with a semi-colon in ':) Link to comment https://forums.phpfreaks.com/topic/12322-error-in-sql-syntax/#findComment-47088 Share on other sites More sharing options...
yarub Posted June 18, 2006 Author Share Posted June 18, 2006 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. >_<; Link to comment https://forums.phpfreaks.com/topic/12322-error-in-sql-syntax/#findComment-47091 Share on other sites More sharing options...
zq29 Posted June 18, 2006 Share Posted June 18, 2006 You can convert to entities with htmlentities() or you can escape the quotes with str_replace() Link to comment https://forums.phpfreaks.com/topic/12322-error-in-sql-syntax/#findComment-47093 Share on other sites More sharing options...
yarub Posted June 18, 2006 Author Share Posted June 18, 2006 Oh. I knew that too. Haha. Thanks a lot for your help. Link to comment https://forums.phpfreaks.com/topic/12322-error-in-sql-syntax/#findComment-47094 Share on other sites More sharing options...
zq29 Posted June 18, 2006 Share Posted June 18, 2006 [!--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\" /] Link to comment https://forums.phpfreaks.com/topic/12322-error-in-sql-syntax/#findComment-47098 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.