So I'm having trouble finding a solution to my problem, which seems like an odd one to begin with to me. Whenever I try to call bind_param on my mysqli prepared statement I'm told "Call to member function bind_param() on non-object." I have a loop to print out the methods of the class, and it has bind_param in the list.
Register.php File
<?php
include('database.php');
if(isset($_SESSION['user'])){
die("You are already logged in ".$_SESSION['user'].", you can't register right now.");
}
register($_POST['username'],$_POST['password'],$_POST['pin'],$_POST['fname'],$_POST['lname'],$_POST['email']);
function register($u,$p,$pi,$f,$l,$e){
/*if($u === "" or $u==="Admin" or $u==="Administrator"){
die("You cannot choose this username");
}*/
if($pi < 0 or $pi > 99999){
die("Invalid Pin number");
}
if($f === "" or $l === ""){
die("Invalid first or last name");
}
if($e === ""){
die("Invalid email");
}
global $conn;
$prep = $conn->prepare("SELECT email FROM users WHERE username=?");
$meth = get_class_methods($prep);
foreach ($meth as $method_name) {
echo "$method_name<br>";
}
$prep->bind_param("s",$u);
$prep->execute();
if($prep->error){
die("User creation failed with the following error: ".$prep->error());
}
if($prep->num_rows > 0){
die("User already exists");
}
$prep->close();
$prep2 = $conn->prepare("INSERT INTO users VALUES(username, password, pin, fname, lname, email,coin) (?,?,?,?,?,?,0)");
$prep2->bind_param("ssisss",$u,$p,$pi,$f,$l,$e);
$prep2->execute();
if(!$prep2->error()){
die("User created successfully");
}else{
die("User creation failed with the following error: ".$prep->error());
}
$prep2->close();
}?>
The database.php file it includes
<?php
$ip = "xo6.x10hosting.com";
$username = "-snip-";
$password = "-snip-";
$database = "-snip-";
$conn = new mysqli($ip, $username, $password, $database);
if ($conn->connect_error or mysqli_connect_error()) {
die("Connection failed: " . $conn->connect_error);
}
if($conn->error){
die("Mysql Error: ".$conn->error);
}?>
I don't get any errors from the database.php file so I don't think the problem is there.