它似乎没有获取$ _POST

时间:2013-09-10 08:46:40

标签: php oracle oracle10g

我被困在登录页面。在家中,用户将登录(表单发送到check_login),并且check_login用户将根据他们的角色定向到页面。但是,我无法通过登录页面。我的意思是我不断从标题中获取错误消息('location:1.php?error = 1');

fyi,我已成功连接到db。数据就在那里。但如果我回显oci_num_rows,结果为0 ..

这是我的代码login.php

<form action="check_login.php" method="post" name="login">
        <div class="error"><?php include('error-handler.php'); ?></div>

        <p> Matric / Staff ID :</p>
        <p><input type="text" name="id" size="20" maxlength="10" onkeypress="return isNumberKey(event)" required value=""/></p>

        <p>Password  :</p>
        <p><input type="password" name="password" id="password" size="20" maxlength="8" min="6" required value="" />
                <script type="text/javascript">
                //add a show password checkbox 
                new ShowPasswordCheckbox(document.getElementById("password"));
                //test the submitted value
                document.getElementById('login').onsubmit = function()
                {
                alert('pword = "' + this.pword.value + '"');
                return false;
                };
        </script>
        </p>
        <p><input type="submit" name="submit" value="Login"/></p> </form>

这是我的check_login.php

    <?php
ob_start();
// Inialize session
session_start();
require_once('connection.php');

//if the login form is submitted
if(isset($_POST['submit']) && !empty($_POST['submit']))
{
    $id = $_POST['id'];
    $pass = $_POST['password'];

    $stmt2= oci_parse($conn, "SELECT * FROM user1 WHERE id = '$id'")or die(oci_error());
    $check2 = oci_execute($stmt2);

     //Gives error if user dosen't exist
     $check3 = oci_num_rows($stmt2);

       if ($check3 == 0)
       {  
       header('location: 1.php?error=1'); //the msg will be: you are not eligible user.
        exit();
       }
       else
       {
        while($info2=oci_fetch_array($stmt2,OCI_ASSOC+OCI_RETURN_NULLS))
            {
            //gives error if the password is wrong
            if ($pass != $info2['password'])
            {
            header('location: 1.php?error=2'); //password mismatch with id
            exit();
            }
            else
            {
            // if login is ok then we add a cookie
            $_SESSION['id'] = $_POST['id'];
            $_SESSION['password'] = $_POST['password'];
            $hour = time() + 86400;

            setcookie(ID_site, $_SESSION['id'], $hour);
            setcookie(Pass_site, $_SESSION['password'], $hour);

            //then redirect them to the members area
                if ($info2['role']=='admin')
                {
                header('Location: homeAdmin.php');
                }
                elseif ($info2['role']=='staff')
                {
                header('Location: homeStaff.php');
                }
                elseif ($info2['role']=='student')
                {
                header('Location: homeStudent.php');
                }
                else
                {
                header('Location: 1.php');
                }

            } //end else

         } //end while

}//end else

}// end if submit
 else
{
 header('Location: 1.php');
 } 

 ?>

如果我错了,请分享您的意见或纠正。谢谢。 :)

1 个答案:

答案 0 :(得分:0)

来自PHP手册'oci_num_rows':http://php.net/manual/en/function.oci-num-rows.php

  

此功能不返回选定的行数!对于SELECT   语句此函数将返回行数,即   使用oci_fetch *()函数获取缓冲区。