I know this type of question answered some where but I am unable to find and solve my issue. I Use MySQLi for login, its work properly on localhost but fire error (Fatal error: Call to a member function query() on a non-object /* PATH */ on line 14) on server. My Localhost version is (php : 5.5.12 and apache 2.4.9) and server version is (php 5.3.27).
Here is my php code
<?php
include 'includes/loginheader.php';
if (isset($_REQUEST['email']))
{
$username = $_REQUEST['email'];
$password = $_REQUEST['password'];
//$username = mysqli_real_escape_string($mysqli, $username);
//$query = mysqli_query($con,"SELECT * FROM user");
//$result = mysqli_query($query);
$sql = "SELECT * FROM admin";
$result = $con->query($sql);
if(mysqli_num_rows($result) == 0) // User not found. So, redirect to login_form again.
{
?>
<script>
$( document ).ready(function() {
$("#diverrorpanel").removeClass('hide');
$("#diverrormsg").text('Username/ Email Not Found');
});
</script>
<?php
}
$userData = mysqli_fetch_array($result, MYSQLi_ASSOC);
$hash = hash('sha256', $userData['salt'] . hash('sha256', $password) );
if($hash != $userData['password']) // Incorrect password. So, redirect to login_form again.
{
?>
<script>
$( document ).ready(function() {
$("#diverrorpanel").removeClass('hide');
$("#diverrormsg").text('Invalid Password');
});
</script>
<?php
}else{ // Redirect to home page after successful login.
ob_start();
session_start();
$_SESSION['email'] = $username;
header('Location: dashboard.php');
//echo "Success";
}
}
?>