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
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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.