Jump to content

mysql_real_escape_string Error


princeofpersia

Recommended Posts

Hi guys, I have a php file where users can register, when I have the code below, it easily echos out the $firstname

 


include ('../includes/db/connecttodb.php')

if (isset($_POST['signup']) && isset($_POST['signup'])) { 

$firstname =$_POST['firstname']; 


echo"$firstname";
}

 

BUT, when I have the same code with mysql_real_escape_string, it give me error below is the code:

 

 


include ('../includes/db/connecttodb.php')

if (isset($_POST['signup']) && isset($_POST['signup'])) { 

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


echo"$firstname";
}

 

and this is my error

 

 

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'user'@'localhost' (using password: NO) in /home/user/public_html/3343/Account/Create/index.php on line 23

 

 

any ideas? I have even inserted query to my db, so its not the connection, the error appears when I have mysql_real_escape_string added to my variable

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/239526-mysql_real_escape_string-error/
Share on other sites

thanks for reply, much appreciated however, made anther connection to my db and now I have db connection in same file (index.php) and this is the error i get

 

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in /home/user/public_html/3343/Account/Create/index.php on line 23

 

 

any thoughts?

Looks like the same problem to me.  mysql_real_escape_string uses an active database connection.  It can be explicitly passed as a parameter, but like a lot of mysql functions, if you don't pass one, php tries to find a connection that it can use.  This warning is telling  you again that the mysql connection it's trying to use is not valid.

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.