dq_1984 2016-11-15 08:31
浏览 54

PHP-HTML-ORACLE我在脚本上有错误

Hi guys i'm a beginner with php and html can u help me to solve this problem?

It gives me this error Warning: oci_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\login.php on line 15

this is my code :

<?php 
session_start();
// connect to database
if (isset($_POST['login_btn'])) {
    $username =$_POST['username'];
    $password =$_POST['password'];
    $conn = oci_connect('socialdb', '12345', 'localhost/XE');
    if (!$conn) {
        $e = oci_error();
        trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
    }
    $password = md5($password); // remember we hashed password before storing last time
    $sql = oci_parse($conn,"SELECT * FROM ACCOUNT WHERE username='$username' AND password='$password'");
    $result =oci_execute($sql);
    if (oci_num_rows($result) == 1) {
        $_SESSION['message'] = "You are now logged in";
        $_SESSION['username'] = $username;
        header("location: home.php"); //redirect to home page
    } else{
        $_SESSION['message'] = "Username/password combination incorrect";
    }
}
?>

UPDATE:Maybe the problem is in the HTML form :

<!DOCTYPE html>
<html>
<head>
    <title>Register, login and logout user php oracle</title>
    <link rel="stylesheet" type="text/css" href="stylea.css">
</head>
<body>
<div class="header"> 
    <h1>Register, login and logout user php oracle</h1>
</div>
<?php
    if (isset($_SESSION['message'])) {
        echo "<div id='error_msg'>".$_SESSION['message']."</div>";
        unset($_SESSION['message']);
    }
?>


<form method="post" action="login.php">
    <table>
        <tr>
            <td>Username:</td>
            <td><input type="text" name="username" class="textInput"></td>
        </tr>

        <tr>
            <td>Password:</td>
            <td><input type="password" name="password" class="textInput"></td>
        </tr>

        <tr>
            <td></td>
            <td><input type="submit" name="login_btn" value="Login"></td>
        </tr>
    </table>
</form>
</body>
</html>

Thank you and sorry for my bad english.

</div>
  • 写回答

1条回答 默认 最新

  • doushihu5475 2016-11-15 08:34
    关注

    Try to check query result validity first, then pay attention since oci_execute returns a boolean, refer to this link for an example

    $result = oci_execute($sql);
    if ($result) {
        if (oci_num_rows($sql) == 1) {
            $_SESSION['message'] = "You are now logged in";
            $_SESSION['username'] = $username;
            header("location: home.php"); //redirect to home page
        } else{
            $_SESSION['message'] = "Username/password combination incorrect";
        }
    } else {
        $_SESSION['message'] = "Query error";
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件