Hi so i am trying to make a login system using mysql and php but i constantly get the error
Warning: mysql_connect(): Access denied for user 'testuser'@'localhost' (using password: YES) in E:\PHP_Runner\php\root\process.php on line 10
The user is created as seen in the
Any suggestions/help?
<?php
$username = $_POST['user'];
$password = $_POST['pass'];
$username = stripcslashes($username);
$password = stripcslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
mysql_connect("localhost",$username, $password) or die("Could not connect to database");
mysql_select_db("users");
$result = mysql_query("select * from users where username = '$username' and password = '$password'")
or die("Failed to query database" .mysql_error());
$row = mysql_fetch_array($result);
if($row['username'] == $username && $row['password'] == $password){
echo "Login success !! welcome".$row['username'];
}else{
echo "Failed to login";
}
?>
To connect to mysql db phpmyadmin or any interface you will need to have mysql login credentials which is not a user login credentials this is usually set at the installation of mysql or you will be using the default. Now this set credentials will replace mysql_connect("localhost", $TheSetUserNameForMysqlDb, $TheSetPasswordForMysqlDb) I hope this help
Which I don't recommend using the default
mysql connect should be something like
mysql_connect("localhost","root", ""); // if you use phpmyadmin in localhost. here root is the defualt admin username of mysql and default password is empty.