警告:oci_fetch_array()期望参数1是资源,布尔值

时间:2013-09-10 03:52:39

标签: php oracle

您好我正在寻找关于上述问题LINE 66的一些帮助。我可以看到有几个mysql用户遇到了和我一样的问题,但在尝试解决方案后,似乎错误仍然存​​在。这是我的代码。

check_login.php

    if(isset($_POST['submit']) && !empty($_POST['submit']))

{

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

         //Gives error if user dosen't exist
     //$check3 = oci_num_rows($check2); <-- if I uncomment this, it will result in an error too.

       if (!$check2) //it supposely if($check3<0)
       {
       header('location: index.php?error=10');
            exit();
       }
       else
       {
        while($info2=oci_fetch_array($check2)) // <----- Error in this line (line 66).
            {
            $pass=$info2['password'];
            //gives error if the password is wrong
            if ($_POST['password'] != $pass)
            {
            header('location: index.php?error=14');
            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: index.php');
                }

            } //end else

         } //end while

}//end else

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

1 个答案:

答案 0 :(得分:1)

oci_execute always returns a boolean。基本上,oci_execute返回db语句是否有效,但它将语句的结果存储在首先保存语句的传递变量中。因此,如果您将错误行更改为此,您应该没问题:

while ($row = oci_fetch_array($stmt2, OCI_ASSOC+OCI_RETURN_NULLS)) {