PHP脚本不适用于登录表单

PHP脚本不适用于登录表单,php,login-script,Php,Login Script,我使用会话变量制作了一个登录表单。此登录表单是index.php,此表单操作将在继续之前将其重定向到validate.php页面。 php代码包含以下内容 <?php session_start(); // Initialize session include('config.php'); // Include database connection settings $sql= mysql_query(

我使用会话变量制作了一个登录表单。此登录表单是index.php,此表单操作将在继续之前将其重定向到validate.php页面。 php代码包含以下内容

<?php
session_start();                    // Initialize session           
include('config.php');              // Include database connection settings
$sql= mysql_query("select * from users where (username= '". mysql_real_escape_string($_post['uname'])."') and (password='".mysql_real_escape_string($_post['pass'])."')");  // Retrieve username and password from database according to user's input
    // check if the username and password exists
    if(mysql_num_rows($sql)==1)
    {
        // store the USERNAME in SESSION VARIABLE
        $_SESSION['name'] = $_POST['uname']; 
        // and then JUMP to WELCOME page
        header('Location:welcome.php');
    }
    else
    {
        // Jump to login page
        //echo "<script type='javascript'>{alert('Username Or Password Incorrect')
//      return false;
//      }
        header('Location:index.php');
    }

?>

$\u post['pass']和$\u post['uname']未定义。使用
$\u POST['pass']
$\u POST['uname']

$\u POST必须大写。此外,我建议先将$\u POST['uname']存储在变量中,然后在查询中使用。

您可能有一个以前登录时设置的剩余会话$\u SESSION[“name”]
。@Pekka我在所有浏览器中都尝试过,它仍然显示相同。$\u POST['uname']和$\u POST['uname']在php中相同吗。如果不是,那么您在Validate.php中写错了。还要检查您是否获得了正确的值echo$_POST['uname']和echo$_POST['pass']。在index.php上,您的标记是单独的,编写代码错误?设置错误级别以显示php调试通知。$sql=“select*from users where(username=”。mysql_real_escape_字符串($_POST['uname'])。“)和(password=”。mysql_real_escape_字符串($_POST['pass'])。”; 然后echo$sql;我错过了帽子。它应该是邮寄的,而不是邮寄的。谢谢
<?php
session_start();                // function to start the session 

if (isset($_SESSION['name']))   // Check, if user is already login, then jump to Welcome page
    {
        header('Location: welcome.php');
    }
?>
</head>
<title>Login</title>

<body>
<form action="validate.php" method="post" name="log"/>
<h3 align="center" style="margin-top:40px">User Login</h3>
<table border="1" cellpadding="3" cellspacing="0" width="40%" align="center" style="margin-top:60px">
<tr>
    <td>User Name</td>
    <td >
        <input type="text" name="uname"/>
    </td>
</tr>
<tr>
    <td>Password</td>
    <td>
        <input type="password" name="pass"/>
    </td>
</tr>
<tr>
    <td colspan="2" align="center">
        <input type="submit" value="Submit">
        <input type="reset" value="Clear ">
    </td>
</tr>
</table>
</body>
</html>