I'm not sure what's going wrong here. I was just following a tutorial online and these errors popped up.
I'm getting the following errors
Error
Notice: Undefined variable: db in C:xampphtdocswisconsindairyfarmersadminlogin.php on line 7
Fatal error: Call to a member function query() on null in C:xampphtdocswisconsindairyfarmersadminlogin.php on line 7
Code
<?php
$db = new mysqli('127.0.0.1', 'root', '', 'wisconsindairyfarmers');
?>
<?php
require '../db/connect.php';
require '../functions/general.php';
function user_exists($username){
//$username = sanitize($username);
$result = $db->query("SELECT COUNT(UserId) FROM users WHERE UserName = '$username'");
if($result->num_rows){
return (mysqli_result($query, 0) == 1) ? true : false;
}}
if(empty($_POST) === false){
$username = $_POST['username'];
$password = $_POST['password'];
if(empty($username) === true || empty($password) === true){
echo 'You need to enter a username and password';
}
else if(user_exists($username) === false) {
echo 'We can't find that username.';
}
}
?>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…