Forum Moderators: coopster

Message Too Old, No Replies

acess denied to use mysql real escape string

         

bleak26

11:19 am on Oct 14, 2006 (gmt 0)

10+ Year Member



Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user: 'nobody@localhost'

I am using the function beneath as an attempt to sanitise, some user input. When i run this code i recive the error above. Does Any one no what causes this error?

<?php

function safe( $string ) {
$string = "'" . mysql_real_escape_string( $string ) . "'";
$string = htmlentities( $value, ENT_QUOTES, 'utf-8' );
return $string;
}
$data = "blah;/ ']";
$test = safe($data);
echo $data;
?>

bleak26

12:15 pm on Oct 14, 2006 (gmt 0)

10+ Year Member



Turns out i needed a database link in code before the rest.

eelixduppy

12:53 am on Oct 16, 2006 (gmt 0)



Glad you figured that out. mysql_real_escape_string() takes a connection handler and escapes the string according to the current character set. Although depreciated, mysql_escape_string [us3.php.net] doesn't need a connection. I'd stick to what you have, though, if you can ;)