0

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.

2
  • please check your sql on db first "SELECT * FROM ACCOUNT WHERE username='$username' AND password='$password'". check that are you getting results for given user and password or not. or u may have more then 1 row for this sql. Commented Nov 15, 2016 at 8:38
  • 1 have just 1 row in my table and it works. Commented Nov 15, 2016 at 8:56

1 Answer 1

1

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";
}
Sign up to request clarification or add additional context in comments.

7 Comments

i still have this Warning: oci_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\login.php on line 16
Now it works but if i insert the right "username" and "password" it gives me that they r incorrect, can u help me?:D I tryed the select form the db and it works
Are you sure $username and $password variables content is right? Are you sure oci_num_rows() doesn't return a number > 1?
I'm sure i use the same variables,i have just 2 rows in my table but with different username.I use an html form for the input maybe is there the problem?
Please echo $sql content and post it
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.