s1yman Posted August 21, 2008 Share Posted August 21, 2008 Hi, I have a form that contains text areas to input to my DB, my question is how do I stop quotation marks, inverted commas, and other punctuation from confusing the script when the form is submitted? Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/120748-solved-problem-with-puncuation-in-input-form/ Share on other sites More sharing options...
s1yman Posted August 21, 2008 Author Share Posted August 21, 2008 I just read something about htmlentities() on google, but anyone have an idea how I would fit this into my form? Link to comment https://forums.phpfreaks.com/topic/120748-solved-problem-with-puncuation-in-input-form/#findComment-622330 Share on other sites More sharing options...
BlueSkyIS Posted August 21, 2008 Share Posted August 21, 2008 i typically single-quote html element parameters, then use htmlentities() thus: $input = $_GET['atextfield']; echo "<input type='text' NAME='atextfield' VALUE='".htmlentities($input, ENT_QUOTES)."' SIZE='20'>"; Link to comment https://forums.phpfreaks.com/topic/120748-solved-problem-with-puncuation-in-input-form/#findComment-622364 Share on other sites More sharing options...
s1yman Posted August 22, 2008 Author Share Posted August 22, 2008 Thanks for the info mate. The punctuation confuses the process script when user clicks submit, so I have tried; <?php $one = htmlentities($_POST['one'],ENT_QUOTES); $sql="INSERT INTO Test2 (one) VALUES ('$one')"; ?> Which strips the code and makes the punctuation stop interfering with the script but still show properly on the display page. The only problem is that I want people to be able to put links and possibly other scripts. Do you know any way to do this? Link to comment https://forums.phpfreaks.com/topic/120748-solved-problem-with-puncuation-in-input-form/#findComment-623396 Share on other sites More sharing options...
Fadion Posted August 23, 2008 Share Posted August 23, 2008 <?php $one = mysql_real_escape_string($_POST['one']); //this will escape all characters that can break your query $one = strip_tags($one, '<a>'); //will remove all html tags except anchors ?> It's not a good idea letting users insert code and then display it to other users. You may end up with exploiters using XSS all the way. It depends on what you want to achieve though, but stripping code is usually a good practice. Link to comment https://forums.phpfreaks.com/topic/120748-solved-problem-with-puncuation-in-input-form/#findComment-623551 Share on other sites More sharing options...
s1yman Posted August 23, 2008 Author Share Posted August 23, 2008 Well my idea is that it is there own page, so if they want to f*ck it up they can. It's not a publicly open form if you get me. thanks for the code Gear! Link to comment https://forums.phpfreaks.com/topic/120748-solved-problem-with-puncuation-in-input-form/#findComment-623688 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.