Jump to content

Trouble passing value to a function and return a value.


funkyapache

Recommended Posts

Hi

 

I have the following php function

function mysql_prep($value){
   $magic_quotes_active = get_magic_quotes_gpc();
   $new_enough_php = function_exists("mysql_real_escape_string"); //used for newer php >= 4.3.0
   if($new_enough_php){
        //undo magic quotes
        if ($magic_quotes_active){$value = stripslashes($value);}
        $value = mysql_real_escape_string($value);
   }else{//before php 4.3
        //if magic quotes not on then addslashes manually
        if (!$magic_quotes_active) {$value=addslashes($value);}
        //if magic quotes is active then the slashes already exists  
   }
   return $value;
} 

 

I tried the following

<?php mysql_prep('Hello'); ?>

 

I do not get back anything I tried echoing the $value as the function starts and that return nothing so my thoughts are that no value is being passed to it.

 

I did a echo on $magic_quotes_active and $new_enough_php and both returned 1. I have no problems with any of my other functions.

 

I am hoping to use this function to escape any special characters before inserting into a mysql table.

Ensure that you have already established a connection to mySQL before calling your mysql_prep() function, otherwise you'll get a False returned by the call to mysql_real_escape_string() and a wraning issued.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.