我现在重新安装了XAMPP,我摆脱了大多数错误。
但我还有一个错误。这一个:
Warning: mysql_connect(): Access denied for user 'admin'@'localhost' (using password: YES) in D:\xampp\htdocs\login_form\login.php on line 7
Could not connect to database.
SQL DATABASE:
login > users >
Id = 1
Username = admin
Password = admin
Id = 2
Username = login_system
Password = login_system
index.php:
<!DOCTYPE html>
<html>
<body>
<form action="login.php" method="POST">
<p>Username : </p><input type="text" name="user">
<p>Password : </p><input type="password" name="pass">
<br>
<input type="submit" value="Login">
</form>
</body>
</html>
的login.php
<?php
//$ = variables?
$username = "admin";
$password = "admin";
$hostname ="localhost";
$database_handle = mysql_connect($hostname, $username, $password) or die ("Could not connect to database.");
$selected = mysql_select_db("login", $database_handle);
$myusername = $_POST['user'];
$mypassword = $_POST['pass'];
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
//Checks if the mySQL database matches the user inputs.
$query = "SELECT * FROM users WHERE Username='".$myusername."' and Password='".$mypassword."'";
$result = mysql_query($query,$database_handle);
$count = mysql_num_rows($result);
if ($count==1){
echo 'Databse connection and code was successful!';
}
?>
它说我需要添加更多我不能的信息。
这里的随机文字..
答案 0 :(得分:0)
请尝试这个并告诉我这是否有效
<?php
//$ = variables?
$username = "root";
$password = "test123";
$hostname ="localhost:8080";
$database_handle = mysql_connect($hostname, $username, $password) or die ("Could not connect to databse. Check your internet connection.");
$selected = mysql_select_db("login", $database_handle);
$myusername = $_POST['user'];
$mypassword = $_POST['pass'];
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
//Checks if the mySQL database matches the user inputs.
$query = "SELECT * FROM users WHERE Username='".$myusername."' and Password='".$mypassword."'";
$result = mysql_query($query,$database_handle);
$count = mysql_num_rows($result);
if ($count==1){
echo 'Databse connection and code was successful!';
}
?>