galvin Posted December 21, 2008 Share Posted December 21, 2008 Just curious if you exprets feel this is a safe enough function to properly prepare text that is getting submitted into a database. If you feel there are better options, please let me know the function names so I can read up on them... <?php function mysql_prep($value) { $magic_quotes_active = get_magic_quotes_gpc(); $new_enough_php = function_exists("mysql_real_escape_string") ; //i.e. PHP >= v4.3.0 if($new_enough_php) { //PHP v4.3.0 or higher //undo any magic quote effects so mysql_real_escape_string can do the work if($magic_quotes_active) { $value = stripslashes($value) ;} $value = mysql_real_escape_string($value); } else { //before php v4.3.0 // if magic quotes aren;t already on then add slashes manually if(!magic_quotes_active) { $value = addslashes($value); } // if magic quotes are active, then the slashes already exist } return $value; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/137920-solved-preparing-text-for-database-insert/ Share on other sites More sharing options...
DeanWhitehouse Posted December 21, 2008 Share Posted December 21, 2008 you could just do mysql_real_escape_string(); Quote Link to comment https://forums.phpfreaks.com/topic/137920-solved-preparing-text-for-database-insert/#findComment-720836 Share on other sites More sharing options...
Mad Mick Posted December 21, 2008 Share Posted December 21, 2008 Unless you are designing scripts for sale, I see no need to provide support for older PHP versions (or at least not as old as v4). If your webhosting service does not provide PHP5 then its time to change. I would disable magic quotes as standard then just use mysql_real_escape_string(). Quote Link to comment https://forums.phpfreaks.com/topic/137920-solved-preparing-text-for-database-insert/#findComment-720841 Share on other sites More sharing options...
galvin Posted December 21, 2008 Author Share Posted December 21, 2008 Thanks guys! Quote Link to comment https://forums.phpfreaks.com/topic/137920-solved-preparing-text-for-database-insert/#findComment-720849 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.