我正在尝试创建一个登录过程,连接我的 phpmyadmin 中的 AdminLogin2.php 和 admin2 表,但它说访问被拒绝。我不知道我该怎么做才能解决它..希望有人可以在这里帮助我。这是我的代码,谢谢。
`<?php
$host="localhost";
$username="root";
$password="";
$database="finalproject";
$table="admin2";
$AdminID=$_POST['Field1'];
$Password=$_POST['Field3'];
mysql_connect("$host","$password") or die (mysql_error());
#echo"connected";
mysql_select_db("$database") or die (mysql_error());
#echo"database found";
// To protect MySQL injection (more detail about MySQL injection)
$AdminID = stripslashes($AdminID);
$Password = stripslashes($Password);
$AdminID = mysql_real_escape_string($AdminID);
$Password = mysql_real_escape_string($Password);
$sql="SELECT * FROM $admin2 WHERE username='$AdminID' and password='$Password'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:AdminForm.php");
}
else {
echo "Wrong Username or Password";
}
?>
`