turtleman8605 Posted May 31, 2007 Share Posted May 31, 2007 How do I get a web form to not add slashes when someone inputs a quote in a text field? For example see www.morseavenuedesign.com/CinemaSightLines.com/sample_forum.php Quote Link to comment https://forums.phpfreaks.com/topic/53685-slashes-in-web-forms/ Share on other sites More sharing options...
Fergusfer Posted May 31, 2007 Share Posted May 31, 2007 How do I get a web form to not add slashes when someone inputs a quote in a text field? For example see www.morseavenuedesign.com/CinemaSightLines.com/sample_forum.php That depends on how and why the slashes are being added. It's difficult to diagnose the problem without the code. I have seen this problem manifest when code escaped strings twice before submitting it to the database, resulting in some of the escape characters themselves being saved. Quote Link to comment https://forums.phpfreaks.com/topic/53685-slashes-in-web-forms/#findComment-265362 Share on other sites More sharing options...
per1os Posted May 31, 2007 Share Posted May 31, 2007 For database entry, I suggest using this function to escape the data instead of "addslashes" if that is what you are using. <?php function myEscape($string) { return get_magic_quotes_gpc()?addcslashes(stripslashes ($string), "\x00\n\are\\'\"\x1a" ):addcslashes($string, "\x00\n\are\\'\"\x1a" ); } foreach ($_REQUEST as $key => $val) { $_REQUEST[$key] = myEscape($val); } ?> If you just want to strictly display/email the data than I would do this: <?php foreach ($_REQUEST as $key => $val) { $_REQUEST[$key] = stripslashes($val); } ?> Note I used $_REQUEST because unsure if you are using get or post, feel free to substitute either or. Quote Link to comment https://forums.phpfreaks.com/topic/53685-slashes-in-web-forms/#findComment-265633 Share on other sites More sharing options...
wintallo Posted May 31, 2007 Share Posted May 31, 2007 Yah, you need to use stripslashes() to... strip the slashes wherever in your code where you output the database data. Also, when inputting data into the mySQL, I would use mysql_real_escape_string() as apposed to addslashes(). Quote Link to comment https://forums.phpfreaks.com/topic/53685-slashes-in-web-forms/#findComment-265679 Share on other sites More sharing options...
turtleman8605 Posted May 31, 2007 Author Share Posted May 31, 2007 Thanks a lot. That worked perfectly. Quote Link to comment https://forums.phpfreaks.com/topic/53685-slashes-in-web-forms/#findComment-265826 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.