创建check_login页面时出现错误
无法选择数据库:用户拒绝访问" @' localhost'到数据库' clg'。
我在phpMyAdmin中创建了表。 我该如何解决这个问题?
这里是完整的代码:
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="clg"; // Database name
$tbl_name="hr"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die('cannot connect:' . mysql_error());
mysql_select_db("$db_name")or die('cannot select DB:' . mysql_error());
//Define $username and $password
$userid = $_POST['userid'];
$password=$_POST['password'];
// To protect MySQL injection (more detail about MySQL injection)
$userid = stripslashes($userid);
$password = stripslashes($password);
$userid = mysql_real_escape_string($userid);
$password = mysql_real_escape_string($password);
$sql="SELECT * FROM $tbl_name WHERE userid='$userid' 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("userid");
session_register("password");
header("location:login_success.php");
} else {
echo "Wrong Username or Password";
}
答案 0 :(得分:0)
我认为您应该向用户授予权限,可能使用phpmyadmin。
见这里:http://dev.mysql.com/doc/refman/5.1/en/adding-users.html