Rovch Posted March 25, 2012 Share Posted March 25, 2012 So I wrote a question/answer script, and I am having issues with inputting symbols. It works great it you only have letters, number, dots, commas, and likely other symbols. However query fails every time you insert certain symbols. Here is an 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 '" ' ''' \ | / ) // ')' at line 3 My test input was following: ' " ' ''' \ | / ) // I am not sure which symbol causes this, and I need help fixing this. How do I go about this without stripping any symbols? Maybe change table structure somehow? Quote Link to comment https://forums.phpfreaks.com/topic/259676-sql-query-error-not-sure-whats-best-in-this-situation/ Share on other sites More sharing options...
titan21 Posted March 25, 2012 Share Posted March 25, 2012 It's probably the quotes - can you post the SQL when the query is generated so we can see what it's choking on? Quote Link to comment https://forums.phpfreaks.com/topic/259676-sql-query-error-not-sure-whats-best-in-this-situation/#findComment-1330897 Share on other sites More sharing options...
Rovch Posted March 25, 2012 Author Share Posted March 25, 2012 It's probably the quotes - can you post the SQL when the query is generated so we can see what it's choking on? Of course, here it is: mysql_query("INSERT INTO wt_answers (id, question_id, user_id, date, title, body) VALUES ('null','$themeid', '$id', '$todays_date', '$_POST[title]', '$_POST[body]')") or die(mysql_error()); Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/259676-sql-query-error-not-sure-whats-best-in-this-situation/#findComment-1331051 Share on other sites More sharing options...
scootstah Posted March 25, 2012 Share Posted March 25, 2012 You'll need to escape your data first. mysql_real_escape_string Quote Link to comment https://forums.phpfreaks.com/topic/259676-sql-query-error-not-sure-whats-best-in-this-situation/#findComment-1331060 Share on other sites More sharing options...
Rovch Posted March 26, 2012 Author Share Posted March 26, 2012 You'll need to escape your data first. mysql_real_escape_string Awesome, thank you! Quote Link to comment https://forums.phpfreaks.com/topic/259676-sql-query-error-not-sure-whats-best-in-this-situation/#findComment-1331082 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.