我将更新用户个人资料详细信息(姓名,密码,contact_no,电子邮件)。 请帮我查一下如何改进代码,以便我能够成功更新。
这是DbOperations.php updateUser类:
public function updateUser($user_id, $name, $password,$contact_no,$email){
$stmt = $this->con->prepare("UPDATE `mydb.User` SET `name` = ?, `password`= ? , `contact_no`= ?,`email` = ? WHERE `user_id` = ? ;");
$stmt->bind_param("ssisi", $name, $password, $contact_no, $email, $user_id);
if($stmt->execute()){
return 1;
}else{
return 2;
}
}
这是updateProfile.php
<?php
require_once'../includes/DbOperations.php';
$response =array();
if($_SERVER['REQUEST_METHOD']=='POST'){
if(isset($_POST['user_id'])and
isset($_POST['name'])and
isset($_POST['password'])and
isset($_POST['contact_no'])and
isset($_POST['email']))
{//operate the data further
$db = new DbOperations();
$result=$db->updateUser(
$_POST['user_id'],
$_POST['name'],
$_POST['password'],
$_POST['contact_no'],
$_POST['email']
);
if($result == 1){
$response['error']= false;
$response['message'] = "updated successfully";
}elseif($result == 2){
$response['error']=true;
$response['message'] = "updated failed";
}
}
}else{
$response['error']=true;
$response['message'] = "empty fileds";
}
echo json_encode($response);
错误信息:
`<br />
<b>Fatal error</b>: Call to a member function bind_param() on a non-object in
<b>C:\xampp\htdocs\Android\includes\DbOperations.php</b> on line
<b>49</b>
<br />`
第49行是:$stmt->bind_param("sssss", $name, $password, $contact_no, $email, $user_id);
我正在使用API开发人员进行POST:
答案 0 :(得分:0)
有两件事,我注意到了
您的SQL中有分号 Date: Sun, 14 Jan 2018 09:35:09 GMT
Server: WSGIServer/0.1 Python/2.7.14+
X-Frame-Options: SAMEORIGIN
Content-Type: text/html; charset=utf-8
Content-Length: 146
和大括号 ;
,这不应该是其中的一部分。它应该是
()
由于,"UPDATE `mydb.User` SET `name` = ?, `password`= ? , `contact_no`= ?,`email` = ? WHERE `user_id` = ?"
和userid
为contact_no
。然后它应该是integer
而不是"ssisi"
另外,我建议使用"sssss"
代替User
。
答案 1 :(得分:0)
$ ./toupper
argv[0] = ./toupper
String in upper case : SOME STRING
$ ./tolower
argv[0] = ./tolower
String in lower case : some string
语句的update
条款没有围绕它的括号。只需删除它们就可以了:
set