princeofpersia Posted June 16, 2011 Share Posted June 16, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/239526-mysql_real_escape_string-error/ Share on other sites More sharing options...
gizmola Posted June 16, 2011 Share Posted June 16, 2011 It's telling you clearly you don't have an active/valid mysql connection resource available. It's attempting to make one using user@localhost with no password. Quote Link to comment https://forums.phpfreaks.com/topic/239526-mysql_real_escape_string-error/#findComment-1230397 Share on other sites More sharing options...
princeofpersia Posted June 16, 2011 Author Share Posted June 16, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/239526-mysql_real_escape_string-error/#findComment-1230400 Share on other sites More sharing options...
gizmola Posted June 16, 2011 Share Posted June 16, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/239526-mysql_real_escape_string-error/#findComment-1230408 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.