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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started