I have this error shown in the browser: Notice: Undefined variable: link in C:\xampp\htdocs\xxxx\login.php on line 40
Hi! The browser shows the errors below in php after clicking login. so it fails to go to home page It shows the following errors Connected successfully Notice: Undefined variable: link in C:\xampp\htdocs\social\login.php on line 40 Warning: mysqli_prepare() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\social\login.php on line 40 The code below: <?php // Initialize the session session_start(); // Check if the user is already logged in, if yes then redirect him to Home page if(isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true){ header("location: home.php"); exit; } // Include config file require_once "connect.php"; // Define variables and initialize with empty values $username = $password = ""; $username_err = $password_err = ""; // Processing form data when form is submitted if($_SERVER["REQUEST_METHOD"] == "POST"){ // Check if username is empty if(empty(trim($_POST["UserName"]))){ $username_err = "Please enter username."; } else{ $username = trim($_POST["UserName"]); } // Check if password is empty if(empty(trim($_POST["Password"]))){ $password_err = "Please enter your Password."; } $password = trim($_POST["Password"]); } // Validate credentials if(empty($username_err) && empty($password_err)){ // Prepare a select statement $sql = "SELECT id, UserName, Password FROM members WHERE username = ?"; if($stmt = mysqli_prepare($link, $sql)){ //line 40 here echo mysqli_error($conn); // Bind variables to the prepared statement as parameters mysqli_stmt_bind_param($stmt, "s", $param_username); // Set parameters $param_username = $username; // Attempt to execute the prepared statement if(mysqli_stmt_execute($stmt)){ // Store result