Mancent Posted December 23, 2012 Share Posted December 23, 2012 I want to allow users to insert into database but i have to prevent them from inserting in tags, how can I do that? I understand the post, and how to insert, but how do I check that no tags where wrote in? This is a ok inseart <td>this is not a ok insert</td> or any other tag Quote Link to comment https://forums.phpfreaks.com/topic/272305-when-i-insert-into-database-how-can-i-not-allow-tags-and/ Share on other sites More sharing options...
thara Posted December 23, 2012 Share Posted December 23, 2012 Clearly, what do you want to do here. How do you try to insert data into the database? Quote Link to comment https://forums.phpfreaks.com/topic/272305-when-i-insert-into-database-how-can-i-not-allow-tags-and/#findComment-1400975 Share on other sites More sharing options...
Manixat Posted December 23, 2012 Share Posted December 23, 2012 (edited) php strip_tags() NOTE: You can also allow them to insert tags, and use htmlspecialchars() when you're displaying the text, so that it doesn't mess up your html Good luck! Edited December 23, 2012 by Manixat Quote Link to comment https://forums.phpfreaks.com/topic/272305-when-i-insert-into-database-how-can-i-not-allow-tags-and/#findComment-1400977 Share on other sites More sharing options...
Christian F. Posted December 23, 2012 Share Posted December 23, 2012 (edited) I recommend the use of htmlspecialchars () over strip_tags (), as the latter function have some caveats that might very well end up messing up/preventing your users from submitting legit content. Primarily this is because of something just looks like it might be a HTML tag, strip_tags () will remove it. So anything starting with a < is subject to removal, even if it's not properly closed. Edited December 23, 2012 by Christian F. Quote Link to comment https://forums.phpfreaks.com/topic/272305-when-i-insert-into-database-how-can-i-not-allow-tags-and/#findComment-1400984 Share on other sites More sharing options...
Mancent Posted December 23, 2012 Author Share Posted December 23, 2012 (edited) Thank you guys you are a big help! In flash i can pass strings to strings, so if this.text.string ="SOMETHING"; i can call that sting anytime i want and place it any where. for example this.newtext.string =""; <--NOTHING but if i need that to == what this.text.string is i would just do this. this.text.string=this.newtext.string; can I do that in html? you see my whole site was made in flash, and most of it still is, but I am trying to make it again in html5 and php and html and javascript.. Edited December 23, 2012 by Mancent Quote Link to comment https://forums.phpfreaks.com/topic/272305-when-i-insert-into-database-how-can-i-not-allow-tags-and/#findComment-1401020 Share on other sites More sharing options...
Manixat Posted December 23, 2012 Share Posted December 23, 2012 (edited) I guess you mean you want to compare 2 strings? Because in PHP == means is equal to, then yes you can do that, but in case you want to see if this.text.string is empty you can check it with the built in function empty() In case I misunderstood and you wanna set this.text.string to this.newtext.string it is as simple as $string1=$string2 All of that is done in PHP, html cannot compile logic, only elements which are going to be displayed on the page ( well not only but basically ) Edited December 23, 2012 by Manixat Quote Link to comment https://forums.phpfreaks.com/topic/272305-when-i-insert-into-database-how-can-i-not-allow-tags-and/#findComment-1401027 Share on other sites More sharing options...
Mancent Posted December 23, 2012 Author Share Posted December 23, 2012 That makes scene. its the same thing. I can just use the $_GET to get the string and then just set it again if needed.. in php Quote Link to comment https://forums.phpfreaks.com/topic/272305-when-i-insert-into-database-how-can-i-not-allow-tags-and/#findComment-1401032 Share on other sites More sharing options...
Manixat Posted December 23, 2012 Share Posted December 23, 2012 (edited) Well $_GET is nothing but an associative array filled with variables from the url. Say you have your file index.php and you address it like this index.php?variable=value&more_variables=more_values Then you can do print_r($_GET) to see what it contains, every value that has been set in this or the $_POST array can be modified Edited December 23, 2012 by Manixat Quote Link to comment https://forums.phpfreaks.com/topic/272305-when-i-insert-into-database-how-can-i-not-allow-tags-and/#findComment-1401035 Share on other sites More sharing options...
Christian F. Posted December 23, 2012 Share Posted December 23, 2012 (edited) It sounds like you might want to read up on variable scope in PHP, and how that relates to functions (and classes). It should be noted that while the examples in the PHP manual use the global keyword, and the $_GLOBALS superglobal, you should use neither. Instead you should pass the variables as parameters to the functions, and use return to get the data back from a function. Also, since you seem to be mixing PHP and HTML, it can be advantageous to think about PHP as the logic layer, and HTML as the presentation layer. HTML itself doesn't do any logic, as Manixat stated above, it only displays static content. PHP, on the other hand, is executed on the server and generates the HTML content that is sent to the client. Separate those (as well as JS and MySQL, if you use them) from each other and things will be a lot easier to handle. Edited December 23, 2012 by Christian F. Quote Link to comment https://forums.phpfreaks.com/topic/272305-when-i-insert-into-database-how-can-i-not-allow-tags-and/#findComment-1401038 Share on other sites More sharing options...
Mancent Posted December 24, 2012 Author Share Posted December 24, 2012 (edited) Hi can you guys help me with this again.. Im trying to do a simple hide and show. with as2 its objectsname._visible=true; or false; html css <style> #this{ visibility:hidden; visibility:visible; } </style> What i am trying to do is, hide the upload button until the file is selected, once it is selected, then we see the upload button. Its something simple and it seems so hard! <style> #this{ visibility:hidden; visibility:visible; } </style> <script type="text/javascript"> function check_if_file_selected() { var file = document.getElementById("selectfile"); if(file.value =="") { alert( 'LETS GET THE IMAGE FILE'); } else { alert('WE ALREADY HAVE A IMAGE FILE SELECTED'); } } </script> <form enctype="multipart/form-data" action="upload_background.php?UserId=5" method="POST"> <input id ="selectfile" onclick="check_if_file_selected()" type="file" name="x" accept="image/*"/> <button id="uploadback" type="submit" >click</button> </form> Edited December 24, 2012 by Mancent Quote Link to comment https://forums.phpfreaks.com/topic/272305-when-i-insert-into-database-how-can-i-not-allow-tags-and/#findComment-1401080 Share on other sites More sharing options...
Manixat Posted December 29, 2012 Share Posted December 29, 2012 You don't need to check on click, simply use <input id ="selectfile" onchange="show button function here" type="file" name="x" accept="image/*"/> Quote Link to comment https://forums.phpfreaks.com/topic/272305-when-i-insert-into-database-how-can-i-not-allow-tags-and/#findComment-1402003 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.