PHP给出致命错误

时间:2015-07-01 22:46:38

标签: php fatal-error

我正在尝试为iOS应用程序创建一个登录屏幕,而我的php正在给我一个错误,我无法找到答案。

错误:

  

注意:尝试获取非对象的属性   /Applications/XAMPP/xamppfiles/htdocs/Registration/MySQLDao.php on   第67行

     

致命错误:/Applications/XAMPP/xamppfiles/htdocs/Registration/MySQLDao.php:67中的未捕获异常'异常'   堆栈跟踪:#0   /Applications/XAMPP/xamppfiles/htdocs/registration/UserRegister.php(41):   MySQLDao-> registerUser(NULL,'d41d8cd98f00b20 ......')#1 {main}引入   /Applications/XAMPP/xamppfiles/htdocs/Registration/MySQLDao.php on   第67行

MySQLDao.php:

<?php
class MySQLDao {
var $dbhost = null;
var $dbuser = null;
var $dbpass = null;
var $conn = null;
var $dbname = null;
var $result = null;

function __construct() {
$this->dbhost = Conn::$dbhost;
$this->dbuser = Conn::$dbuser;
$this->dbpass = Conn::$dbpass;
$this->dbname = Conn::$dbname;
}

public function openConnection() {
$this->conn = new mysqli($this->dbhost, $this->dbuser, $this->dbpass,      $this->dbname);
if (mysqli_connect_errno())
echo new Exception("Could not establish connection with database");
}

public function getConnection() {
return $this->conn;
}

public function closeConnection() {
if ($this->conn != null)
$this->conn->close();
}

public function getUserDetails($email)
{
$returnValue = array();
$sql = "select * from users where user_email='" . $email . "'";

$result = $this->conn->query($sql);
if ($result != null && (mysqli_num_rows($result) >= 1)) {
$row = $result->fetch_array(MYSQLI_ASSOC);
if (!empty($row)) {
$returnValue = $row;
}
}
return $returnValue;
}

public function getUserDetailsWithPassword($email, $userPassword)
{
$returnValue = array();
$sql = "select id,user_email from users where user_email='" . $email .  "' and user_password='" .$userPassword . "'";
$result = $this->conn->query($sql);
if ($result != null && (mysqli_num_rows($result) >= 1)) {
$row = $result->fetch_array(MYSQLI_ASSOC);
if (!empty($row)) {
$returnValue = $row;
}
}
return $returnValue;
}

public function registerUser($email, $password)
{
$sql = "insert into users set user_email=?, user_password=?";
$statement = $this->conn->prepare($sql);

if (!$statement)
throw new Exception($statement->error);//LINE 67

$statement->bind_param(“ss”, $email, $password);
$returnValue = $statement->execute();

return $returnValue;
}

}
?>

UserRegister.php:

<?php
require("Conn.php");
require("MySQLDao.php");
if (isset($_POST['email']) ) {
$email = htmlentities($_POST['email']);
echo $email;
} elseif (isset($_POST['password']) ) {
$password = htmlentities($_POST['password']);
echo $password;
}
$returnValue = array();
echo "DDDD";

if(!empty($email) || !empty($password))
{
$returnValue["status"] = "error";
$returnValue["message"] = "Missing required field";
echo json_encode($returnValue);
return;
} else {
$returnValue["status"] = "SUCCESS";
$returnValue["message"] = "REGISTERED";
echo json_encode($returnValue);
}

$dao = new MySQLDao();
$dao->openConnection();
$userDetails = $dao->getUserDetails($email);

if(!empty($userDetails))
{
$returnValue["status"] = "error";
$returnValue["message"] = "User already exists";
echo json_encode($returnValue);
return;
}

$secure_password = md5($password); // I do this, so that user password     cannot be read even by me

$result = $dao->registerUser($email,$secure_password);

if($result)
{
$returnValue["status"] = "Success";
$returnValue["message"] = "User is registered";
echo json_encode($returnValue);
return;
}

$dao->closeConnection();

?>

我之前从未见过这样的错误,我搜索了谷歌,发现没有帮助我的解决方案。有人知道造成这个错误的原因以及如何修复它吗?

任何帮助表示赞赏!谢谢!

0 个答案:

没有答案