mysql_real_escape_string(); Is Not Working

Hello,

I am having some trouble with the mysql_real_escape_string() function.
It is giving me a warning each time I run the page…

"Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user ‘eric’@‘localhost’ (using password: NO) in /public_html/index.php on line 24

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in /public_html/index.php on line 24"

<?php

@$link = new mysqli("localhost", "eric", "pass", "db");

if ($link->connect_error) {

die ("Error: " . $link->connect_error);

}

echo mysql_real_escape_string("Hi!");

@$link->close();

?>

What is wrong here?

Its not working because you can’t mix MySQL functions with MySQLi, please read the following documentation on how to use mysqli_real_escape_string().

PHP: mysqli::real_escape_string - Manual

Hi again,

I see now…
I did not realize there was a MySQLi form of it.
That fixes that issue!

Thank you. :slight_smile:

No problem