Question: PHP login application. ERROR: Every time I run this it gives me this error, line 42 is in black so you can see it. Any

PHP login application.

ERROR: Every time I run this it gives me this error, line 42 is in black so you can see it. Any help is appreciated!!! thanks!!

Notice: Trying to get property 'num_rows' of non-object in /opt/lampp/htdocs/Project/login.php on line 42

$conn = new mysqli('localhost', 'root', ''); if($conn === false){ die("ERROR: Could not connect. " . mysqli_connect_error()); } $cookie_name = '';

if(isset($_COOKIE[$cookie_name])) { echo "Welcome to our site"; echo " "; echo " Logout "; }

$show_form = false; $login_result = $usernameErr = $passwordErr = '' ;

if($_SERVER["REQUEST_METHOD"] == "POST"){ if(isset($_POST["submit"])){

extract($_POST);

if(empty($username)){ $usernameErr = "Please fill out username"; $show_form = true; }

if(empty($password)){ $passwordErr = "Please fill out the password"; $show_form = true; } if( (!empty($username)) && (!empty($password)) && (!$show_form)){ $password = md5($password);

$search = " SELECT * FROM `login` WHERE `username` = '$username' AND `password` = '$password' "; $result = $conn->query($search);

if($result->num_rows == 1){ $row = $result->fetch_assoc();

echo "Welcome to our site"; echo " "; echo " Logout ";

if(isset($remember_me)) { $cookie_name = "user"; $cookie_value = $row['username']; setcookie($cookie_name, $cookie_value, time() + (86400 * 7), "/"); }

$conn->close(); } else{ echo "Invalid credentails"; $show_form = true;}

} else{ $login_result = "Invalid credentials" ; $show_form = true; }

}

}

else { $show_form = true; }

if($show_form){ ?>

Username:
Password:
Remember me

}

?>

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!