Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Databases On The Web Learn To Create Web Pages That Interface With Database Engines

Authors: Robert Papaj, Donald Burleson

11th Edition

1576100995, 978-1576100998

More Books

Students also viewed these Databases questions

Question

Discuss the different types of leadership

Answered: 1 week ago

Question

Write a note on Organisation manuals

Answered: 1 week ago

Question

Define Scientific Management

Answered: 1 week ago

Question

Explain budgetary Control

Answered: 1 week ago