phpjayx Posted January 8, 2013 Share Posted January 8, 2013 Whenever I insert a ' as part of a string is comes out as for example: Johnny\'s How do go and replace that with some character code string that works... ? Doing google searches isn't getting me very far in this... Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/272832-insering-a-to-a-mysql-database-problems/ Share on other sites More sharing options...
requinix Posted January 8, 2013 Share Posted January 8, 2013 Turn off the magic_quotes php.ini setting, and make sure you're safe against SQL injection. Quote Link to comment https://forums.phpfreaks.com/topic/272832-insering-a-to-a-mysql-database-problems/#findComment-1404114 Share on other sites More sharing options...
DavidAM Posted January 8, 2013 Share Posted January 8, 2013 ... comes out as ... Where exactly does it "come out" with a backslash? In the database? In a web page? Somewhere else? You should be using an appropriate escaping function, such as mysql_real_escape_string, before writing a value to the database. But you should not be using that same function on data being sent to a web page. Which means you should only escape for the database when building the query. WRONG $name = mysql_real_escape_string($_POST['name']); $sql = "INSERT INTO table VALUES('$name')"; echo $name; NOT WRONG $name = $_POST['name']; $sql = "INSERT INTO table VALUES('" . mysql_real_escape_string($name) . "')"; echo htmlspecialchars($name); Quote Link to comment https://forums.phpfreaks.com/topic/272832-insering-a-to-a-mysql-database-problems/#findComment-1404115 Share on other sites More sharing options...
Barand Posted January 8, 2013 Share Posted January 8, 2013 A requinix said, it's the magic_quotes. If ON, your data has slashes added automatically, so "O'Donnel" is passed from the form as "O\'Donnel". If you then addslashes or real_escape the data it becomes "O\\\'Donnel" which then gets written the database as "O\'Donnel" Quote Link to comment https://forums.phpfreaks.com/topic/272832-insering-a-to-a-mysql-database-problems/#findComment-1404256 Share on other sites More sharing options...
phpjayx Posted January 9, 2013 Author Share Posted January 9, 2013 Interesting... I found it, turned it off, its still inserting / into my database.... Really its from the Initial PHP form -->.JS--->PHP (looking in my Charles debugger, it shows correct in the Posting)-, then using the $name= $_POST['name']; --->.JS --->php to write it to MySQL database It messes up somehwere in these last few transfers, which I'm not exactly sure where..... Still hunting. Quote Link to comment https://forums.phpfreaks.com/topic/272832-insering-a-to-a-mysql-database-problems/#findComment-1404369 Share on other sites More sharing options...
jazzman1 Posted January 9, 2013 Share Posted January 9, 2013 After you turned it off, did you restart the web server? Quote Link to comment https://forums.phpfreaks.com/topic/272832-insering-a-to-a-mysql-database-problems/#findComment-1404412 Share on other sites More sharing options...
phpjayx Posted January 10, 2013 Author Share Posted January 10, 2013 Ahhhh I did not restart the server.... thanks for that......! Quote Link to comment https://forums.phpfreaks.com/topic/272832-insering-a-to-a-mysql-database-problems/#findComment-1404574 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.