When I enter the username and password I get a warning like this:
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, array given in /home/data/www/z1760359/public_html/group/connectivity.php on line 18
And
Incorrect password or username.
I have typed the correct credentials . The structure of my database is:
member ID firstName lastName userName password
Here are my index.php and connectivity.php
index.php
<?php
session_start();
?>
<html>
<head>
<style>
#login
{
position:absolute;
top: 30%;
bottom: 30%;
left:30%;
right:30%;
margin: 0px auto;
}
</style>
</head>
<body>
<?php
echo"<center>";
echo"<div id=\"login\">";
echo"<form method=\"POST\" action=\"connectivity.php\">";
echo"<b>Username</b> <input type =\"text\" name=\"username\">";
echo"<br/><br/>";
echo"<b>Password</b> <input type =\"password\" name=\"password\">";
echo"<br/><br/>";
echo"<input type=\"submit\" value=\"submit\">";
echo"</div>";
echo"</center>";
?>
</body>
</html>
Connectivity
<?php
$username = $_POST['username'];
$password = $_POST['password'];
$host="localhost";
$uname="user";
$pword="";
$db="z1760359";
$conn=mysqli_connect($host,$uname,$pword,$db) or die("Oops something went wrong");
session_start();
$query="Select firstName from member where userName='$username' AND password='$password'";
if(!empty($_POST['username']))
{
$query_first=mysqli_query($conn,$query) or die(" Query not retrieved");
//mysqli_error($query_first);
$query_second=mysqli_fetch_assoc($query_first);
$rows=mysqli_num_rows($query_second);
if($rows ==1)
{
$_SESSION['user_name']=extract($query_second);
echo"login successfull";
sleep(3);
header('Location:search.php');
}
else
{
echo"Incorrect Password or Username";
}
}
else
{
echo"please enter the password or username";
}
?>