Warning: mysql_real_escape_string(): Access denied for user 'root'@'localhost' (using password: NO) …/public_html/checklogin.php

后端 未结 3 1808
太阳男子
太阳男子 2021-01-29 14:07

Thank you guys for the wonderful job you are doing. I just uploaded my website on the the remote server and it brought me back this error message.

Warning: mysq         


        
3条回答
  •  春和景丽
    2021-01-29 15:03

    The problem is you use mysql_real_escape_string() function first then you connect:

    $username = mysql_real_escape_string($_POST['username']);
    $password = mysql_real_escape_string($_POST['password']);
    
    mysql_connect("50.28.8.6", "root","") or die(mysql_error()); //Connect to server
    

    Solution is to connect first then use function mysql_real_escape_string()

    //Connect to server
    mysql_connect("50.28.8.6", "root","") or die(mysql_error()); 
    $username = mysql_real_escape_string($_POST['username']);
    $password = mysql_real_escape_string($_POST['password']);
    

    This is because mysql_real_escape_string() requires the connection.

提交回复
热议问题