本人刚学PHP,不知道下面代码的第三行到底哪里错了,麻烦高人指点!
在浏览器中老是出现这个问题:
Notice: Undefined index: form in D:\SQL\SQL SERVER 2005\34\login.php on line 3以下是源代码:
<?php
session_start();
if($_POST["form"] == "form1") //获得表单信息并插入
{
include("inc/conn.php");
if(trim($_POST["username"]) == "")
{
echo "用户名不能为空 <a href='login.php'>返回</a>";
exit;
}
if(trim($_POST["password"]) == "")
{
echo "密码不能为空 <a href='login.php'>返回</a>";
exit;
}
$username = $_POST["username"];
$password = $_POST["password"];
$query_sql = "select * from Users where username='$username' and password='$password' and eligible='E'";
$query = mssql_query($query_sql, $conn) or die ("用户登录失败 <a href='login.php'>返回</a>");
if(mssql_num_rows($query)>0)
{
echo "用户登录成功 <a href='index.php'>返回首页</a>";
$_SESSION["username"] = $username;
reclog($conn, $username, "login.php", "用户登录成功"); //记录日志
exit;
}
else
{
echo "用户名、密码不正确或用户名无效 <a href='login.php'>返回</a>";
reclog($conn, $username, "login.php", "用户登录失败"); //记录日志
exit;
}
exit;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>用户登录</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
.style1 {
font-size: 16px;
font-weight: bold;
}
.style3 {font-size: 12px}
-->
</style>
</head><body>
<?php
include("inc/head.php");
?>
<p align="center" class="style1">用户登录</p>
<form name="form1" method="post" action="">
  <table width="300" border="1" align="center" cellpadding="0" cellspacing="0">
    <tr>
      <td width="118"><div align="right" class="style3">(*)用户名:</div></td>
      <td><input name="username" type="text" id="username"></td>
    </tr>
    <tr>
      <td><div align="right" class="style3">(*)密码:</div></td>
      <td><input name="password" type="password" id="password"></td>
    </tr>
  </table>
  <p align="center">
    <input type="hidden" name="form" value="form1">
    <input type="button" value="用户注册" onclick="location.href='reg.php'">
    <input type="submit" value="用户登录"><BR>
    <input type="button" value="忘记密码" onclick="location.href='fgtpwd.php'">
    <input type="reset" value="表单重置">
  </p>
</form>
<?php
include("inc/foot.php");
?>
</body>
</html>
这个是conn.php代码<?php 
$server_host = ".\\SQLEXPRESS"; //
$server_user = "root";
$server_pwd = "123456";
$db_name = "myshop";
$conn = mssql_connect($server_host, $server_user, $server_pwd)
or die("Cannot connect to SQL Server 2005"); //连接SQL Server
mssql_select_db($db_name, $conn) 
or die("Cannot connect to MYSHOP database.");  //选择要使用的数据库
include("inc/log.php");
?>

解决方案 »

  1.   

    include("inc/conn.php"); 这里的路径是否正确?
      

  2.   

    且我说所的源代码就是login.php
      

  3.   

    action="";这里不能为空 否则你要提交给那个页面处理呢?
      

  4.   


    写上了提交页面,出现另外一个问题:
    Fatal error: Call to undefined function mssql_connect() in D:\SQL\SQL SERVER 2005\34\Inc\conn.php on line 6可在运行login.php时就出现这个问题了
    Notice: Undefined index: form in D:\SQL\SQL SERVER 2005\34\login.php on line 3if($_POST["form"] == "form1") 
    这行老到底哪里哪里错了呢?
    还是说其他原因?
      

  5.   

    if($_POST["form"] == "form1") 
    去掉就ok 本页面提交又是一个表单不需要
      

  6.   


    去掉以后,页面不再显示了,出现了另外问题:
    Fatal error: Call to undefined function mssql_connect() in D:\SQL\SQL SERVER 2005\34\Inc\conn.php on line 6
    我在数据库能用root登录的,mssql_connect()里面的参数我又没有写错,那到底是哪里出问题呢?
      

  7.   

    连接SQL SERVER2005 需要什么配置之类的吗?
      

  8.   

    看错了 把<form name="form1" method="post" action="">该成
    <form  name="form1" method="post" action="<?=$_SERVER['PHP_SELF']; ?>">还不行?
      

  9.   

    <?php
    session_start();
    if($_POST["form"] == "form1")            //获得表单信息并插入
    {
        include("inc/conn.php");
        if(trim($_POST["username"]) == "")
        {
            echo "用户名不能为空 <a href='login.php'>返回</a>";
            exit;
        }
        if(trim($_POST["password"]) == "")
        {
            echo "密码不能为空 <a href='login.php'>返回</a>";
            exit;
        }
        $username = $_POST["username"];
        $password = $_POST["password"];
        $query_sql = "select * from Users where username='$username' and password='$password' and eligible='E'";
        $query = mssql_query($query_sql, $conn) or die ("用户登录失败 <a href='login.php'>返回</a>");
        if(mssql_num_rows($query)>0)
        {
            echo "用户登录成功 <a href='index.php'>返回首页</a>";
            $_SESSION["username"] = $username;
            reclog($conn, $username, "login.php", "用户登录成功");        //记录日志
            exit;
        }
        else
        {
            echo "用户名、密码不正确或用户名无效 <a href='login.php'>返回</a>";
            reclog($conn, $username, "login.php", "用户登录失败");        //记录日志
            exit;
        }
        exit;
    }
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>用户登录</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <style type="text/css">
    <!--
    .style1 {
        font-size: 16px;
        font-weight: bold;
    }
    .style3 {font-size: 12px}
    -->
    </style>
    </head><body>
    <?php
    include("inc/head.php");
    ?>
    <p align="center" class="style1">用户登录</p>
    <form name="form1" method="post" action="<?=$_SERVER['PHP_SELF']; ?>">
      <table width="300" border="1" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td width="118"><div align="right" class="style3">(*)用户名:</div></td>
          <td><input name="username" type="text" id="username"></td>
        </tr>
        <tr>
          <td><div align="right" class="style3">(*)密码:</div></td>
          <td><input name="password" type="password" id="password"></td>
        </tr>
      </table>
      <p align="center">
        <input type="hidden" name="form" value="form1">
        <input type="button" value="用户注册" onclick="location.href='reg.php'">
        <input type="submit" value="用户登录"><BR>
        <input type="button" value="忘记密码" onclick="location.href='fgtpwd.php'">
        <input type="reset" value="表单重置">
      </p>
    </form>
    <?php
    include("inc/foot.php");
    ?>
    </body>
    </html>提交action改了以后测试没有问题