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 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图