Posted By

sebikovacs on 07/06/10


Tagged

mysql Value prep


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

cigraphics


Prepare value for database


 / Published in: PHP
 

  1. function mysql_prep($value){
  2. $magic_quote_active = get_magic_quotes_gpc();
  3. $new_enough_php = function_exists("mysql_real_escape_string");//returns true if PHP>v4.3
  4. if($new_enough_php){
  5. //undo magic quotes damege
  6. if($magic_quote_active){$value = stripslashes($value);}
  7. $value=mysql_real_escape_string($value);
  8. }else{
  9. //if no magic quotes add slashes
  10. if(!$magic_quote_active){$value=addslashes($value);}
  11. }
  12. return $value;
  13.  
  14. }

Report this snippet  

You need to login to post a comment.