delickate Posted February 17, 2012 Share Posted February 17, 2012 Hi, I'm inserting data into database. which is going fine. but i want to make sure how to insert secure data into database to avoid sql injection. what function should i use to insert secure data into database. can any one guide me please??? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/257153-help-secure-input/ Share on other sites More sharing options...
darkfreaks Posted February 17, 2012 Share Posted February 17, 2012 you can use mysql_real_escape_string or PDO i would go with PDO it is more secure in my opinion. Quote Link to comment https://forums.phpfreaks.com/topic/257153-help-secure-input/#findComment-1318209 Share on other sites More sharing options...
delickate Posted February 17, 2012 Author Share Posted February 17, 2012 thanks for the reply, what is PDO? can u give me an example of that? e.g: if we code for mysql_real_escape_string() like this echo "insert into table(feidlname) values('".mysql_real_escape_string($value) ."')"; how would we do code for PDO? like this echo "insert into table(feidlname) values('".PDO($value) ."')"; please guide thanks Quote Link to comment https://forums.phpfreaks.com/topic/257153-help-secure-input/#findComment-1318223 Share on other sites More sharing options...
darkfreaks Posted February 17, 2012 Share Posted February 17, 2012 http://www.phpro.org/tutorials/Introduction-to-PHP-PDO.html#4.3 Quote Link to comment https://forums.phpfreaks.com/topic/257153-help-secure-input/#findComment-1318233 Share on other sites More sharing options...
delickate Posted February 17, 2012 Author Share Posted February 17, 2012 Thanks alot. you are really helpful. Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/257153-help-secure-input/#findComment-1318238 Share on other sites More sharing options...
cyberRobot Posted February 17, 2012 Share Posted February 17, 2012 You'll also want to validate / sanitize the data, if you haven't done so already. For example, if a field is supposed to be a number, you could check by using something like ctype_digit(): <?php if( ctype_digit( (string) $numToTest) ) { print "Number; continue processing"; } else { print "Not a number; flag error"; } ?> If selecting one of several radio buttons in a form, make sure the value corresponds with one of the options. If the value isn't supposed to contain HTML / PHP tags, you could run strip_tags() to remove them. http://php.net/manual/en/function.strip-tags.php Quote Link to comment https://forums.phpfreaks.com/topic/257153-help-secure-input/#findComment-1318342 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.