mga_ka_php Posted August 11, 2010 Share Posted August 11, 2010 i have a textarea and the content is description. how do i save this to database, because sometimes it has ' and " so it fails when i insert it into database, what should i use addslashes? Quote Link to comment https://forums.phpfreaks.com/topic/210405-textarea-into-database/ Share on other sites More sharing options...
linus72982 Posted August 11, 2010 Share Posted August 11, 2010 mysql_real_escape_string($CONTENT, $CONNECTION); Actually, I'm not positive that will escape ANDs, but you should use that on all input anyway. Quote Link to comment https://forums.phpfreaks.com/topic/210405-textarea-into-database/#findComment-1097919 Share on other sites More sharing options...
mga_ka_php Posted August 11, 2010 Author Share Posted August 11, 2010 so mysql_real_escape_string removes the quotes? Quote Link to comment https://forums.phpfreaks.com/topic/210405-textarea-into-database/#findComment-1097928 Share on other sites More sharing options...
linus72982 Posted August 11, 2010 Share Posted August 11, 2010 From php.net: mysql_real_escape_string — Escapes special characters in a string for use in an SQL statement Yep, it escapes the quotes. PHP.net recommends you use this in place of addslashes() if possible. Quote Link to comment https://forums.phpfreaks.com/topic/210405-textarea-into-database/#findComment-1097934 Share on other sites More sharing options...
mga_ka_php Posted August 11, 2010 Author Share Posted August 11, 2010 ok thanks Quote Link to comment https://forums.phpfreaks.com/topic/210405-textarea-into-database/#findComment-1097936 Share on other sites More sharing options...
Festy Posted August 11, 2010 Share Posted August 11, 2010 Although you can also use addslashes and stripslashes, using 'mysql_real_escape_string' would also help you prevent any sql injection attempts. Quote Link to comment https://forums.phpfreaks.com/topic/210405-textarea-into-database/#findComment-1097948 Share on other sites More sharing options...
xcoderx Posted August 11, 2010 Share Posted August 11, 2010 this function could be handy function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } Quote Link to comment https://forums.phpfreaks.com/topic/210405-textarea-into-database/#findComment-1097964 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.