My problem is that I cannot require a page before I start my class code.It doesn't show any errors on finding the page,but it does show some errors that the variable I am trying to access is undefined. I'm trying to access $conn from the class. Here is my code:
<?php
$conn = mysqli_connect("localhost","root","")or die(mysqli_connect_error());
$database = mysqli_select_db($conn,'purchaseproject');
if(!$database){
echo 'error'.mysqli_error($connect);
}
?>
<?php
require_once './connection.php';
class memberCheck{
static public function isAdmin(){
$email="foo";
$sql="SELECT admin FROM members WHERE email='$email'";
$query=mysqli_query($conn,$sql);
var_dump($sql);
}
static public function usernameAvailable($email){
}
}
$mc=memberCheck::isAdmin();
?>
I tried changing require_once with require,but it didn't work.So I put it inside the function and it worked fine,yet I'm going to have more than one method and I don't want to copy the same code everywhere.
What do you think about my problem?