gpt4 book ai didi

php - 将帐户信息更新到数据库不起作用,PHP 错误 : "Call to a member function"

转载 作者:行者123 更新时间:2023-11-29 09:27:37 24 4
gpt4 key购买 nike

我正在开发一个使用 SharedPreferences 登录的应用程序。如果用户想从应用程序内更新其信息,下一步是添加更新数据库的 Activity 。我已经写了代码,但是当我运行它时,JSON似乎有问题。我已经使用断点进行了检查,并且值都正常,但是“s=”部分显示 Error: Call to a member function bind_param() on bool in C:\Users\wamp64\www\App.php on line <i>189</i>所以,我进入我的 php 并检查了第 189 行,但我没有看到任何错误。我使用了精确的登录/注册语法,它的效果非常好。谢谢!

首先,我将添加 .php 中的第 189 行:

$stmt->bind_param("ssss", $nume, $prenume, $email, $telefon);

更新信息.java

class ActualizareUser extends AsyncTask<Void, Void, String> {

@Override
protected String doInBackground(Void... voids) {
//creating request handler object
RequestHandler requestHandler = new RequestHandler();

//creating request parameters
HashMap<String, String> params = new HashMap<>();
params.put("nume", Nume);
params.put("email", Email);
params.put("prenume", Prenume);
params.put("telefon", Telefon);
params.put("id", id);

//returing the response
return requestHandler.sendPostRequest(URLs.URL_UPDATE_USER, params);
}

@Override
protected void onPreExecute() {
super.onPreExecute();
//displaying the progress bar while user registers on the server
}

@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
//hiding the progressbar after completion
try {
//converting response to json object
JSONObject objs = new JSONObject(s);

//if no error in response
if (!objs.getBoolean("error")) {
Toast.makeText(getApplicationContext(), objs.getString("message"), Toast.LENGTH_SHORT).show();

//getting the user from the response
JSONObject userJson = objs.getJSONObject("user");

//creating a new user object
User user = new User(
userJson.getString("Nume"),
userJson.getString("Prenume"),
userJson.getString("Adresa_mail"),
userJson.getString("Numar_telefon"),
userJson.getString("Parola"),
userJson.getInt("ID_UTILIZ")
);

//storing the user in shared preferences
SharedPrefManager.getInstance(getApplicationContext()).userLogin(user);
finish();
startActivity(new Intent(getApplicationContext(), Profil.class));
} else {
Toast.makeText(getApplicationContext(), "A aparut o eroare", Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}

App.php ,更新部分:

case 'updateuser':


if(isTheseParametersAvailable(array('nume','email','prenume', 'telefon', 'id'))){
$prenume = $_POST["prenume"];
$nume =$_POST["nume"];
$email =$_POST["email"];
$telefon =$_POST["telefon"];
$id =$_POST["id"];

$stmt = $conn->prepare("SELECT ID_UTILIZ FROM informatii_persoane WHERE ID_UTILIZ = ?");
$stmt->bind_param("s", $id);
$stmt->execute();
$stmt->store_result();

if($stmt->num_rows < 1){
$response['error'] = true;
$response['message'] = 'Nu se poate identifica un cont';
$stmt->close();
}else{
$stmt = $conn->prepare("UPDATE INTO informatii_persoane (Nume, Prenume, Adresa_mail, Numar_telefon) VALUES (?, ?, ?, ?)");
$stmt->bind_param("ssss", $nume, $prenume, $email, $telefon);

if($stmt->execute()){
$stmt = $conn->prepare("SELECT ID_UTILIZ, Nume, Prenume, Adresa_mail, Numar_telefon, Parola FROM informatii_persoane WHERE Adresa_mail = ?");
$stmt->bind_param("s",$email);
$stmt->execute();
$stmt->bind_result($id, $nume, $prenume, $email, $telefon, $parola);
$stmt->fetch();

$user = array(
'Nume'=>$nume,
'Prenume'=>$prenume,
'Adresa_mail'=>$email,
'Numar_telefon'=>$telefon,
'Parola'=>$parola,
'ID_UTILIZ'=>$id
);

$stmt->close();

$response['error'] = false;
$response['message'] = 'Date actualizate cu success';
$response['user'] = $user;
}
}

}else{
$response['error'] = true;
$response['message'] = 'A aparut o eroare';
}

break;

更新的.php:

case 'updateuser':
if(isTheseParametersAvailable(array('nume','email','prenume', 'telefon', 'id'))){
$prenume = $_POST["prenume"];
$nume =$_POST["nume"];
$email =$_POST["email"];
$telefon =$_POST["telefon"];
$id =$_POST["id"];

$stmt = $conn->prepare("SELECT ID_UTILIZ FROM informatii_persoane WHERE ID_UTILIZ = ?");
$stmt->bind_param("s", $id);
$stmt->execute();
$stmt->store_result();
$rows = $stmt->num_rows;
$stmt->close();

if($rows < 1){
$response['error'] = true;
$response['message'] = 'Nu se poate identifica un cont';

}else{
$stmt = $conn->prepare("UPDATE INTO informatii_persoane (Nume, Prenume, Adresa_mail, Numar_telefon) VALUES (?, ?, ?, ?)");
$stmt->bind_param("ssss", $nume, $prenume, $email, $telefon);

if($stmt->execute()){
$stmt1 = $conn->prepare("SELECT ID_UTILIZ, Nume, Prenume, Adresa_mail, Numar_telefon, Parola FROM informatii_persoane WHERE Adresa_mail = ?");
$stmt1->bind_param("s",$email);
$stmt1->execute();
$stmt1->bind_result($id, $nume, $prenume, $email, $telefon, $parola);
$stmt1->fetch();
$stmt1->close();
$user = array(
'Nume'=>$nume,
'Prenume'=>$prenume,
'Adresa_mail'=>$email,
'Numar_telefon'=>$telefon,
'Parola'=>$parola,
'ID_UTILIZ'=>$id
);


$response['error'] = false;
$response['message'] = 'Date actualizate cu success';
$response['user'] = $user;
}
$stmt->close();
}

}else{
$response['error'] = true;
$response['message'] = 'A aparut o eroare';
}

break;

informatii_persoane结构:

   create table if not exists informatii_persoane (
ID_utiliz int auto_increment primary key,
Nume varchar(50),
Prenume varchar(50),
Adresa_mail varchar (50) unique ,
Numar_telefon text ,
Notificare_SMS enum('Da','Nu'),
Notificari_aplicatie enum('Da','Nu'),
Parola varchar(50),
nr_alerte_semnalizate int,
nr_alerte_corecte int,
nr_alerte_partial_corecte int,
nr_lerte_incorecte int, -- vezi aici cum faci %
scor float -- il facem din cele doua de mai sus
);

最佳答案

$stmt = $conn->prepare("Update informatii_persoane set Nume = ?, Prenume = ?, Adresa_mail = ?, Numar_telefon = ?  where ID_UTILIZ = ?");
$stmt->bind_param("ssssi", $nume, $prenume, $email, $telefon, $id);

The problem lies in $stmt->close();

您尚未关闭 select 语句然后启动 insert 语句。您可以同时打开多个语句。但您最终必须关闭它们。

Also, you have written the INSERT query wrong.

检查一下

UPDATE INTO informatii_persoane (Nume, Prenume, Adresa_mail, Numar_telefon) VALUES (?, ?, ?, ?)

更改为

INSERT INTO informatii_persoane (Nume, Prenume, Adresa_mail, Numar_telefon) VALUES (?, ?, ?, ?)

/**************************************************** **************/

Important Note

另外,如果你想找出查询中的错误, 在给出错误的行的下方和上方添加 echo $conn->error;

关于php - 将帐户信息更新到数据库不起作用,PHP 错误 : "Call to a member function",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59301454/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com