简体   繁体   中英

Problem with PHP mysql_real_escape_string

When I run mysql_real_escape_string , for example like this:

$test = mysql_real_escape_string($_POST['test']);

it's not working on local server, it gives me an error page!

  • my local server is " AppServ ".
  • my operating systim is " windows XP ".

Is this normal? and just i have to run it on hosted site only !

You have to provide the function an active database connection. I think it's the second argument:

$test = mysql_real_escape_string($_POST['test'], $mysql_database_connection);

That might be your error, because if you don't provide an active connection explicitly, the function looks for the last one which was created. If you run this function before connecting to the database, it'll give you an error.

We'd need to know which error before we could help you any more, but the most common error that I get when using mysql_real_escape_string is when I forget that it takes a second parameter .

This tells the function which character set you need escaping. You just need to pass the database resource ID.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM