-1
    <?php
    session_start();
    include("conn.php");
    if(isset($_POST['login'])){
    if($_POST['user']=="admin" and $_POST['pass']=="abc123"){
    $_SESSION['user']=1;
    header("location:login.php");
    exit(); }
    else {
    echo "WRONG USERNAME OR PASSWORD";
    }
    }
    ?>

请转换它,以便将用户名和密码与数据库进行比较。数据库是 dbcom,tbluser 有两个字段 user 和 pass...

需要尽快回复,我们的项目时间不多了...非常感谢您的帮助,谢谢

4

2 回答 2

0

尝试喜欢这个:

//set vars
$user = $_POST['user'];
$pass = md5($_POST['pass']);

if ($user&&$pass) 
{
//connect to db
$connect = mysql_connect("$server","$username","$password") or die("not connecting");
mysql_select_db("users") or die("no db :'(");
$query = mysql_query("SELECT * FROM $tablename WHERE username='$user'");

$numrows = mysql_num_rows($query);


if ($numrows!=0)
{
//while loop
  while ($row = mysql_fetch_assoc($query))
  {
    $dbusername = $row['username'];
    $dbpassword = $row['password'];
  }
  else
      die("incorrect username/password!");
}
else
  echo "user does not exist!";
} 
else
    die("please enter a username and password!");
于 2013-10-02T10:14:15.153 回答
0

使用此代码,希望它会有所帮助。

<?php
    session_start();
    include("conn.php");
    $qry=mysql_query("select * from tbluser");
    $credentials=mysql_fetch_array($qry);
    if(isset($_POST['login']))
    {
        if($_POST['user']==$credentials["user"] and $_POST['pass']==$credentials["Pass"])
        {
           $_SESSION['user']=1;
           header("location:login.php");
           exit();
        }
       else 
       {
          echo "WRONG USERNAME OR PASSWORD";
       }
    }
?>
于 2013-10-02T10:17:29.637 回答