我正试图更新我的数据库中某一行中的某些字段,该行是通过电子邮件定义的,但无论我做什么,我都会收到这个错误:
致命错误:在第63行的C:''wamp''www''android_login_api''include''DB_Functions.php中的非对象上调用成员函数bind_param()
这是我用来做这件事的PHP代码:
<?php
ini_set ( 'display_errors', 'On' );
class DB_Functions {
private $conn;
// constructor
function __construct() {
require_once 'DB_Connect.php';
// connecting to database
$db = new Db_Connect ();
$this->conn = $db->connect ();
}
// destructor
function __destruct() {
}
/**
* Storing new user
* returns user details
*/
public function storeUser($name, $email, $password, $latitude, $longitude, $userType) {
$uuid = uniqid ( '', true );
$hash = $this->hashSSHA ( $password );
$encrypted_password = $hash ["encrypted"]; // encrypted password
$salt = $hash ["salt"]; // salt
$service = "none";
$rate = "none";
$rated_clients = "none";
$stmt = $this->conn->prepare ( "INSERT INTO users(unique_id, name, email, encrypted_password, latitude, longitude, userType, salt, service, rate, rated_clients, created_at) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW())" );
$stmt->bind_param ( "sssssssssss", $uuid, $name, $email, $encrypted_password, $latitude, $longitude, $userType, $salt, $service, $rate, $rated_clients );
$result = $stmt->execute ();
$stmt->close ();
var_dump ( $result );
// check for successful store
if ($result) {
$stmt = $this->conn->prepare ( "SELECT * FROM users WHERE email = ?" );
$stmt->bind_param ( "s", $email );
$stmt->execute ();
$user = $stmt->get_result ()->fetch_assoc ();
$stmt->close ();
var_dump ( $user );
echo '</pre>';
return $user;
} else {
return null;
}
}
/**
* Storing data
* returns data details
*/
public function storeData($email, $service, $rate, $rated_clients) {
$stmt = $this->conn->prepare ( "UPDATE users SET service = ? , rate = ? , rated_clients = ? WHERE email = ? " );
$stmt->bind_param ( 'ssss', $service, $rate, $rated_clients, $email );
var_dump ( $stmt->execute () );
if ($stmt->execute ()) {
$data = $stmt->get_result ()->fetch_assoc ();
$stmt->close ();
echo '</pre>';
var_dump ( $data );
return $data;
} else {
return NULL;
}
}
/**
* Get user by email and password
*/
public function getUserByEmailAndPassword($email, $password) {
$stmt = $this->conn->prepare ( "SELECT * FROM users WHERE email = ?" );
$stmt->bind_param ( "s", $email );
if ($stmt->execute ()) {
$user = $stmt->get_result ()->fetch_assoc ();
$stmt->close ();
$salt = $user ["salt"];
$hash = $this->checkhashSSHA ( $salt, $password );
if ($hash == $user ["encrypted_password"]) {
return $user;
} else {
return NULL;
}
} else {
return NULL;
}
}
/**
* Check user is existed or not
*/
public function isUserExisted($email) {
$stmt = $this->conn->prepare ( "SELECT email from users WHERE email = ?" );
$stmt->bind_param ( "s", $email );
$stmt->execute ();
$stmt->store_result ();
if ($stmt->num_rows > 0) {
// user existed
$stmt->close ();
return true;
} else {
// user not existed
$stmt->close ();
return false;
}
}
/**
* Encrypting password
*
* @param
* password
* returns salt and encrypted password
*/
public function hashSSHA($password) {
$salt = sha1 ( rand () );
$salt = substr ( $salt, 0, 10 );
$encrypted = base64_encode ( sha1 ( $password . $salt, true ) . $salt );
$hash = array (
"salt" => $salt,
"encrypted" => $encrypted
);
return $hash;
}
/**
* Decrypting password
*
* @param
* salt, password
* returns hash string
*/
public function checkhashSSHA($salt, $password) {
$hash = base64_encode ( sha1 ( $password . $salt, true ) . $salt );
return $hash;
}
}
?>
更改此项:
$stmt = $this->conn->prepare ( "UPDATE users SET service = ? , SET rate = ? , SET rated_clients = ? WHERE email = ? " );
未来:
$stmt = $this->conn->prepare ( "UPDATE users SET service = ? , rate = ? , rated_clients = ? WHERE email = ? " );