php mysql prepare statement not working <p>I'm currently learning php and mysql and am trying to build an authentication webpage where the user registers and is able to log in to a member protected page. The registration process works fine but for some reason I'm getting this error in my login execution script.</p> <pre><code>Fatal error: Call to a member function prepare() on a non-object in /homepages/8/d459264879/htdocs/tymbi_reg/login_exec.php on line 40 </code></pre> <p>Line 40 is here if($stmt = $mysqli->prepare("SELECT * FROM member WHERE username=? AND password =?"))</p> <p>I've been trying hard to find where the problem is without any success.</p> <p>This is the code that I'm using in my login script</p> <pre><code>&lt;?php session_start(); require_once('connection.php'); $errmsg_arr = array(); $errflag = false; $username = $_POST['username']; $password = $_POST['password']; if($username == '') { $errmsg_arr[] = 'Username missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'Password missing'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); header("location: index.php"); exit(); } else { if($stmt = $mysqli-&gt;prepare("SELECT * FROM member WHERE username=? AND password =?")) { $stmt-&gt;bind_param("ss", $username, $password); $stmt-&gt;execute(); $stmt-&gt;store_results(); if($stmt-&gt;num_rows &gt; 0) { $SESSION['username'] = $username; header("Location: home.php"); } else { $error['alert'] = "Username or password are incorrect"; } } } ?&gt; </code></pre> <p>Here's my connection.php code</p> <pre><code>&lt;?php $con=new mysqli("test","test","test","test"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } ?&gt; </code></pre> <p>And yes, I have replaced the test values with my details</p>