class DbOperations{
private $con;
function __construct(){
require_once dirname(__FILE__).'/db_connected.php';
$db = new DbConnect();
$this->con = $db->connect();
}
public function changePassword($pass){
$password = md5($pass);
$stm = $this->con->prepare("UPDATE `student` SET `password` = ?
WHERE `username` = ?);");
$stm->bind_param("s",$password);
$stm->execute();
if ($stm) {
return true;
}
else {
return false;
}
}
Now this is the function which i want to call for change password in android studio using php script.
All other file are not wrong the main problem is in this script name DbOperations
function changePassword
This is change password script userChangePassword.php
<?php
require_once '../include/db_operations.php';
$response = array();
if ($_SERVER['REQUEST_METHOD']=='POST') {
if (isset($_POST['password'])){
$db = new DbOperations();
if ($db->changePassword($_POST['password'])){
$response['error'] = false;
$response['message'] = "Change Password Successfully";
}
else{
$response['error'] = true;
$response['message'] = "Password not changed";
}
}
else{
$response['error'] = true;
$response['message'] = "Fill all the feilds";
}
}
else{
$response['error'] = true;
$response['message'] = "Invalid Request";
}
echo json_encode($response);
Error is :
Fatal error: Call to a member function bind_param() on a non-object in C:\xampp\htdocs\Android\include\db_operations.php on line 69
答案 0 :(得分:0)
Your error seems to suggest that $stm is not set correctly.
$stm = $this->con->prepare("UPDATE `student` SET `password` = ?
WHERE `username` = ?);");
did not return a valid object. Are all the variables in your __construct function valid?
Edit: duskwuff is right, the closing parenthesis in WHERE username = ?)
is incorrect
答案 1 :(得分:0)
$stm = $this->con->prepare("UPDATE `student` SET `password` = ?
WHERE `username` = ?);");
^
This SQL statement is invalid -- the closing parenthesis I've marked (after `username` = ?
) doesn't have a matching opening parenthesis anywhere. This causes the prepare
call to fail.
$stm->bind_param("s",$password);
$stm->execute();
You haven't bound a value to the second parameter, corresponding to username
. Nor is there a username argument to the function, or even to the userChangePassword.php
script -- how is it supposed to know which user's password to update?