This question already has an answer here:
Ive tried my best to try and fix this multiple time but something is still wrong with the code and I keep getting errors coming from the php
Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /home/a9114464/public_html/api/api.php on line 10
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in /home/a9114464/public_html/api/api.php on line 12
Now here is the api.php file
$conn = mysqli_connect("EXAMPLE", "EXAMPLE", "EXAMPLE");
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
function login($username, $password){
$sql = "SELECT * from users WHERE username='$username' AND password='$password'";
$result = mysqli_query($conn, $sql);
$check_user = mysqli_num_rows($result);
if($check_user>0){
$_SESSION[‘username’]=$username;
}
}
Thanks in advance :)
</div>