PHP-HTML-ORACLE我有一个脚本错误


PHP-HTML-ORACLE i have an error on a script

大家好,我是php和html的初学者,你们能帮我解决这个问题吗?

它给了我这个错误Warning: oci_num_rows() expects parameter 1 to be resource, boolean given in C:'xampp'htdocs'login.php on line 15

这是我的代码:

<?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";
    }
}
?>

更新:也许问题是在HTML的形式:

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

谢谢你,很抱歉我的英语不好

尝试先检查查询结果的有效性,然后注意,因为oci_execute返回一个布尔值,参考此链接获取示例

$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";
}