<?php 
error_reporting(0);   
$mysql_servername ="10.4.250.20";
$mysql_username = "hr";  
$mysql_password ="946138";   
$mysql_database ="hr"; //数据库名
if(isset($_POST['Submit'])){
  $mssql_connect($mysql_servername , $mysql_username , $mysql_password) or die("数据库连接错误!");
  mssql_select_db($mysql_database);   
  mssql_query("SET NAMES 'gbk'");
  $tname=$_POST['txt_user']; 
  $tpassowrd=$_POST['txt_password'];   
 if(empty($tname))
  {
    echo "<script language=javascript>alert('用户名不能为空');history.back();</script>";
    exit;
  }
 
   $sql =" select * from Pip_Staff_S  where cStaffID ='$tname' and cDoorLock='$tpassowrd'";
   echo $sql;
   $res = mssql_query($sql); 
    $rows = mssql_num_rows($res);    
   echo $rows;
   if($rows)
    { 
      echo "<script langrage=javascript>alert('恭喜您登陆成功')</script>";
      echo "<script>window.location.href='Index_STR.php';</script>";
      exit;   
     }
     else
    {
         echo "<script language=javascript>alert('用户名密码错误');history.back();</script>";   
    }
}
?>Html 代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>STR</title>
<style type="text/css">
<!--
.STYLE1 { font-size: 24px;
font-weight: bold;
}
-->
</style>
</head><body>
<form id="form1" name="form1" method="post" action="login1.php">
  <table width="894" height="351" border="0">
    <tr>
      <td width="270" height="110">&nbsp;</td>
      <td width="82">&nbsp;</td>
      <td width="179"><span class="STYLE1">欢迎登录STR</span></td>
      <td width="157">&nbsp;</td>
      <td width="172">&nbsp;</td>
    </tr>
    <tr>
      <td height="36">&nbsp;</td>
      <td>User ID:</td>
      <td><label>
        <input name="txt_user" type="text" id="txt_user" />
      </label></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td height="57">&nbsp;</td>
      <td>Pass Word:</td>
      <td><input name="txt_password" type="password" id="txt_password" /></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td height="63">&nbsp;</td>
      <td><label>
        <div align="right">
          <input type="submit" name="Submit" value="登  录" />
        </div>
      </label></td>
      <td><label>
        &nbsp; &nbsp; &nbsp;<input type="submit" name="Submit2"  value="注  册" onClick="document.location.href='Register.php'"/>
      </label></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td height="17">&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
  <p>&nbsp;</p>
</form>
</body>
</html>
数据库用户名和密码都是正确的为什么我输入正确的用户名和密码是 页面直接跳转到 "login1.php"
应该是跳转到"Index_STR.php".
我连接的是msssql,请问是什么愿?

解决方案 »

  1.   

    把你输出的sql语句放到查询分析器里面执行一下 看下有没有结果
      

  2.   

    输入正确的用户名和密码后,提示了“恭喜你登陆成功”的信息吗?
    mssql是连接Microsoft SQL Server数据库。
      

  3.   

     $sql =" select * from Pip_Staff_S where cStaffID =$tname and cDoorLock=$tpassowrd";  echo "<script langrage=javascript>alert('恭喜您登陆成功')</script>";
      echo "<script>window.location.href='Index_STR.php';</script>";
      exit;   index_str.php 里面有没有判断session,cookie什么的?  
      

  4.   

    我怎么打印不出来,它直接运行显示到"login1.php" 页面.我用 echo $sql;来打印sql语句.
      

  5.   

    这样写跳转是没有问题的..
    是不是index_str.php页面判断cookies为空了.
      

  6.   

    index_str.php 里面没有任何session,cookie的值。。我也没有看到提示了“恭喜你登陆成功”的信息。
      

  7.   

    <form id="form1" name="form1" method="post" action="login1.php"><input type="submit" name="Submit2" value="注 册" onClick="document.location.href='Register.php'"/>
    這兩個地方的問題...
      

  8.   

    $mssql_connect($mysql_servername , $mysql_username , $mysql_password) or die("数据库连接错误!");
    不懂.
      

  9.   

    我判断它没有运行到下列if语句中.
    if($rows)
      {  
      echo "<script langrage=javascript>alert('恭喜您登陆成功')</script>";
      echo "<script>window.location.href='Index_STR.php';</script>";
      exit;   
      }
      else
      {
      echo "<script language=javascript>alert('用户名密码错误');history.back();</script>";   
      }运行到这段代码 就会有对话框弹出来哦?但不知道为什么会直接运行到 "login1.php“页面中??还有,我把window.location.href='Index_STR.php' 换成连接到其他页面去,
    运行后他还是连接到"login1.php“页面中???
      

  10.   

    连接服务器确定没错,,
    我用vb.net连接是成功的。。现在是要用php去连。
      

  11.   

    $mssql_connect($mysql_servername , $mysql_username , $mysql_password) or die("数据库连接错误!");
    ???
    为什么是:$mssql_connect
    应该是:mssql_connect调试程序时不应关闭错误显示!
    即。不能 error_reporting(0);   
    而应该 error_reporting(E_ALL);
    至少也是 error_reporting(E_ALL & ~E_NOTICE);   
      

  12.   

    你的action是login1.php,肯定会跳转到login1.php啦,,按照你的情况应该这样写:action="",就行了