c_pattle Posted February 23, 2011 Share Posted February 23, 2011 I have a form that allows users to submit to a database and for security reasons I am using mysql_real_scape_string on all of their input values. However this means that if the user puts something in speech marks such as "hello" It will then show up in the database as \"hello\" This means that whenever I fetch anything from the database it will have slashes in which doesn't look good. How do other people get round this problem. When I fetch something from my database should I do a string replace and just delete these slashes or is there a better method? Thanks for any help. Quote Link to comment https://forums.phpfreaks.com/topic/228642-mysql_real_escape_string/ Share on other sites More sharing options...
btherl Posted February 23, 2011 Share Posted February 23, 2011 Check that you don't have magic_quotes enabled, and also check that you are not calling mysql_escape_string() twice on the same data. If escaped correctly, you will not have the backslashes in the database. Quote Link to comment https://forums.phpfreaks.com/topic/228642-mysql_real_escape_string/#findComment-1178874 Share on other sites More sharing options...
jaikob Posted February 23, 2011 Share Posted February 23, 2011 Use stripslashes() http://php.net/manual/en/function.stripslashes.php Quote Link to comment https://forums.phpfreaks.com/topic/228642-mysql_real_escape_string/#findComment-1178875 Share on other sites More sharing options...
c_pattle Posted February 23, 2011 Author Share Posted February 23, 2011 Thanks, I don't think I'm escaping the fields twice. I've copied below my code. Am I escaping it twice? $submit_sql = sprintf("insert into reviews (review_name, review_content, review_summary) values (\"%s\", \"%s\", \"%s\")", mysql_real_escape_string($_GET['submit_film_name']), mysql_real_escape_string($_GET['submit_film_content']), mysql_real_escape_string($_GET['submit_film_summary'])); Quote Link to comment https://forums.phpfreaks.com/topic/228642-mysql_real_escape_string/#findComment-1178916 Share on other sites More sharing options...
btherl Posted February 23, 2011 Share Posted February 23, 2011 In that code you pasted, you are escaping the strings once. You probably have magic quotes on. Quote Link to comment https://forums.phpfreaks.com/topic/228642-mysql_real_escape_string/#findComment-1178919 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.