<?php
   session_start();
  
   //连接服务器
   define("HOST","localhost");
   define("USER","root");
   define("PASS","123456");
   $link=mysql_connect(HOST,USER,PASS) or die("连接服务器失败!");
  
   //选择数据库
   mysql_select_db("user",$link) or die("选择数据库失败!");
        
   //判断登录按钮是否被按下
   if($_POST["submit"]=="登录")
   {
           $name=$_POST["name"];
    $pass=$_POST["pass"];
   
    //书写查询SQL语句
    $sql="select * from info where name='$name' or pass='$pass'";
   
    //执行SQL语句
    $result=mysql_query($sql);
   
    //取出记录集中记录的条数
    $num=mysql_num_rows($result);
   
   
   
    if($num>0)
    {  
        $_SESSION["username"]=$name;
        echo "<script>";
        echo "alert('登录成功!');";
        echo "window.location.href='index.php';";
               echo "</script>";  
    }else
    {
        echo "<script>";
        echo "alert('用户名或密码错误!');";
        echo "history.go(-1);";
               echo "</script>";
    }
   }

 

?>