KeemW Posted August 28, 2014 Share Posted August 28, 2014 Hi, below is the error and php that i used for my login page. Error: Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\Sportify\admin\checkauthadmin.php on line 11Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in C:\xampp\htdocs\Sportify\admin\checkauthadmin.php on line 11Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\Sportify\admin\checkauthadmin.php on line 12Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in C:\xampp\htdocs\Sportify\admin\checkauthadmin.php on line 12Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\Sportify\admin\checkauthadmin.php on line 13Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in C:\xampp\htdocs\Sportify\admin\checkauthadmin.php on line 13 Php: <?php //session_start(); $today = date(Ymd); $_SESSION[username] = $_POST['username']; $_SESSION[password] = $_POST['password']; $_SESSION[id] = $_POST['id']; $username = stripslashes($_SESSION[username]); $password = stripslashes($_SESSION[password]); $username = mysql_real_escape_string($_SESSION[username]); $password = mysql_real_escape_string($_SESSION[password]); $id = mysql_real_escape_string($_SESSION[id]); include('connection.php'); $sql_login = "SELECT id FROM admin WHERE username = '$username' and password = '$password'"; $result_login = mysql_query($sql_login); $count_login = mysql_num_rows($result_login); //$row = mysql_fetch_assoc($sql_login); if($count_login == 1) { //session_register("user_email"); //session_register("user_password"); //echo "PASS"; header("location:../admin/main_admin.php"); } else { header("location:admin_login2.php"); } exit; ?> Please guide me. Quote Link to comment https://forums.phpfreaks.com/topic/290696-login-php-problem/ Share on other sites More sharing options...
Solution cyberRobot Posted August 28, 2014 Solution Share Posted August 28, 2014 The calls to mysql_real_escape_string() need to be made after the database connection has been established. Try moving them after the following line: include('connection.php'); Side note: in case you're not aware, the mysql_* function have been deprecated and will be removed in a future version of PHP. If you haven't done so already, you'll need to look into the alternatives at some point: http://php.net/manual/en/mysqlinfo.api.choosing.php Quote Link to comment https://forums.phpfreaks.com/topic/290696-login-php-problem/#findComment-1489132 Share on other sites More sharing options...
KeemW Posted August 28, 2014 Author Share Posted August 28, 2014 Thank you cyberRobot! Problem fixed. Quote Link to comment https://forums.phpfreaks.com/topic/290696-login-php-problem/#findComment-1489133 Share on other sites More sharing options...
cyberRobot Posted August 28, 2014 Share Posted August 28, 2014 No problem; glad to help! Quote Link to comment https://forums.phpfreaks.com/topic/290696-login-php-problem/#findComment-1489134 Share on other sites More sharing options...
KeemW Posted August 28, 2014 Author Share Posted August 28, 2014 I have another problem that i can't solve. Error: Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\Sportify\admin\admin_dashboard.php on line 19Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\xampp\htdocs\Sportify\admin\admin_dashboard.php on line 19Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\Sportify\admin\admin_dashboard.php on line 20 Php: <?php $id = $_GET['id']; $result1 = mysql_query("SELECT * FROM admin WHERE username = '$_SESSION[username]' ORDER BY id"); while ($row1 = mysql_fetch_assoc($result1)) { $name = mysql_result($result1, 0, 'name'); $phone = mysql_result($result1, 0, 'phone'); $email = mysql_result($result1, 0, 'email'); $address = mysql_result($result1, 0, 'address'); } echo "Welcome to Admins Dashboard"; echo "<div style = 'border:0px solid #000;padding:20px;border-radius:15px;'><table width = '30%'> <tr><td colspan =3 style = 'text-align:right;'><a href = 'main_admin.php?page=admin_edit_profile.php&id=$id'><img src = '../images/edit.png' title = 'edit profile' style = 'width:25px;height:25px;'></a> <a href = 'main_admin.php?page=admin_edit_password.php&id=$id'><img src = '../images/changepassword.png' title = 'change password' style = 'width:25px;height:25px;'></a> </td></tr> <tr><td>Name</td><td> : </td><td>$name</td></tr></p>"; echo "<tr><td>Contact</td><td> : </td><td>$phone</td></tr>"; echo "<tr><td>E-Mail Address</td><td> :</td><td> $email</td></tr>"; echo "<tr><td>Address</td><td> :</td><td> $address</td></tr></table></div>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/290696-login-php-problem/#findComment-1489136 Share on other sites More sharing options...
Ch0cu3r Posted August 28, 2014 Share Posted August 28, 2014 Those errors are caused by your original issued you started this topic with. See cyberRobot's post. Before you can use any mysql_ functions you need to make sure you are connected to MySQL. Otherwise you will get the errors you are receiving Quote Link to comment https://forums.phpfreaks.com/topic/290696-login-php-problem/#findComment-1489137 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.