I'm trying to create a simple login using mySQLi with PHP. I have everything set up using a variable $username and $password that holds the login information rather than using post from a form as I just want to get it working first before advancing to this and injection protection. So all in all if the variables match the table in the data base then it prints Logged In! otherwise it'll print Invalid username or password but every time I run this I get an error:
Error:
Warning: mysqli_query() expects parameter 1 to be mysqli, null given
<?
$dbhost = 'localhost';
$dbuser = 'xxxx';
$dbpass = 'xxxx';
$dbname = 'xxxx';
$con = mysqli_connect($dbhost, $dbuser, $dbpass,$dbname);
$sql="SELECT email, pass FROM lg_user";
$username = 'Admin';
$password = "123qweQWE";
$query = "SELECT `user` FROM `lg_user` WHERE `user`='$username' AND `pass`='$password'";
var_dump($query);
if($query_run = mysqli_query($conn,$query)){
$query_num_rows = mysqli_num_rows($query_run);
if($query_num_rows == 0){
print("Invalid username or password");
}
else if($query_num_rows == 1){
print("Logged In!");
}
}
?>