dtcuv8044 2012-05-25 07:11
浏览 42
已采纳

PHP脚本不适用于登录表单

I have made one login form using session variables. This login form is index.php and this form action is redirecting it to a validate.php page before he proceeds further. Vaidate.php code contains this

<?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');
    }

?>

and index.php contains below code

<?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>

This problem is that it is redirecting to index.php even if the username password is right. I'm not able to figure out what I'm missing in this case. Code seems to be right.

  • 写回答

2条回答 默认 最新

  • duandushang5148 2012-05-25 07:16
    关注

    $_post['pass'] and $_post['uname'] are undefined. Use $_POST['pass'] and $_POST['uname'].

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题