PHP Giving Fatal Error -
i'm trying make login screen ios app , php giving me error can't find answer to.
error:
notice: trying property of non-object in /applications/xampp/xamppfiles/htdocs/registration/mysqldao.php on line 67
fatal error: uncaught exception 'exception' in /applications/xampp/xamppfiles/htdocs/registration/mysqldao.php:67 stack trace: #0 /applications/xampp/xamppfiles/htdocs/registration/userregister.php(41): mysqldao->registeruser(null, 'd41d8cd98f00b20...') #1 {main} thrown in /applications/xampp/xamppfiles/htdocs/registration/mysqldao.php on line 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 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 * users 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 users user_email='" . $email . "' , 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 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 exists"; echo json_encode($returnvalue); return; } $secure_password = md5($password); // this, user password cannot read me $result = $dao->registeruser($email,$secure_password); if($result) { $returnvalue["status"] = "success"; $returnvalue["message"] = "user registered"; echo json_encode($returnvalue); return; } $dao->closeconnection(); ?>
i've never seen errors before , searched google , found no solutions helped me. know what's causing error , how fix it?
any appreciated! thanks!!
Comments
Post a Comment