我知道这类问题在某些地方得到了回答,但我无法找到并解决我的问题。 我使用MySQLi进行登录,它在localhost上正常工作但在服务器上出现错误(致命错误:在非对象/ * PATH * /第14行上调用成员函数query())。我的Localhost版本是(php:5.5.12和apache 2.4.9),服务器版本是(php 5.3.27)。
这是我的PHP代码
<?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";
}
}
?>