Forum Moderators: coopster
function q($data,$string=false) {
if(get_magic_quotes_gpc()) {
$data = stripslashes($data);
}
$data = mysql_real_escape_string($data);
if($string) { $data = "'".$data."'"; }
return $data;
}
It did work on my local environment, but once uploaded to the server, this line returned nothing to the $data varriable:
$data = mysql_real_escape_string($data);
What could be wrong?
Could you test this for me on your server:
echo mysql_real_escape_string("test"); It should return and echo out test and we will know if the function is working right on your server. Try with other values other then test which you have parsed to your $data variable.
I tried this:
echo mysql_escape_string("test");
outputs: test
echo mysql_real_escape_string("test");
outputs:
I believe mysql_escape_string is almost the same as the other, with the only difference that the "real" one optionally receives a mysql resource as a parameter.
still strange...
Note: A MySQL connection is required before using mysql_real_escape_string() otherwise an error of level E_WARNING is generated, and FALSE is returned. If link_identifier isn't defined, the last MySQL connection is used.
Make sure you have error reporting on up to warnings:
error_reporting(E_ALL ^ E_NOTICE);
And maybe test the returned value against false, which would indicate an error:
$escaped_string = mysql_real_escape_string("test");
if($escaped_string === false) echo 'oops!';