如果匹配来自数据库的密码,请尝试登录我的管理面板

时间:2015-02-06 09:23:10

标签: php

我已经将用户名和密码放在数据库中,现在我要做的是当管理员输入我存储在数据库中的用户名和密码时,他们可以访问下一页,否则会出错。

if(isset($_REQUEST['submit'])) {
     $user=$_REQUEST['user'];
     $password=$_REQUEST['password'];
     $q = mysql_fetch_assoc( mysql_query("SELECT * FROM adminlogin"));
     $r = mysql_query($q);
     if ( $user == "admin" && $password == "adminadmin" ) {
         echo "welcome";
         Header("Location: index.php");
     }
}

1 个答案:

答案 0 :(得分:0)

试试这个:

if(isset($_REQUEST['submit'])) {
 $user=$_REQUEST['user'];
 $password=$_REQUEST['password'];

 //Execute query, adjust the name of the columns to the one you've used in your table
 $q = mysql_query("SELECT * FROM adminlogin WHERE user = '$user' and password = '$password'");

 //Get the results from the query
 $r = mysql_fetch_array($q);

 //If any rows, the login is okay
 if (mysql_num_rows($q) > 0) {
      //User okay, redirect him to the success page
      header("location: index.php");
}