gpt4 book ai didi

java - INSERT 查询在 SQL 中有效,但在 Android 应用程序中无效

转载 作者:太空狗 更新时间:2023-10-29 13:03:17 25 4
gpt4 key购买 nike

我正在尝试向我的 SQL 数据库发送一个 INSERT 查询,但它不起作用并且没有出现任何错误,但是如果我从 phpMyAdmin 发送它,查询就可以工作。这是我的 PHP 代码:

if ($_POST['func'] == 2) {
$dbca = taskdb();
$dbca->set_charset("utf8");
$mobileUser = $_POST['phone'];
$fullnameUser = $_POST['fullname'];
$usernameUser = $_POST['username'];
$sql = "INSERT INTO users (UserPhone, Username, UserFullname) VALUES (?,?,?)";
$result = $dbca->prepare($sql);
$result->bind_param("sss", $mobileUser,$fullnameUser,$usernameUser);
echo json_encode(array('profileUser' => 'DONE'));
}

这是我在 AsyncT doInBacground 中的 java(客户端)代码:

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://192.168.2.26/MyProject/fetchData.php");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("func", "2"));
nameValuePairs.add(new BasicNameValuePair("phone", Login.user_phone));
nameValuePairs.add(new BasicNameValuePair("fullname", fullname.getText().toString()));
nameValuePairs.add(new BasicNameValuePair("username", username.getText().toString()));
Log.e("mainToPost", "mainToPost" + nameValuePairs.toString());
UrlEncodedFormEntity form;
form = new UrlEncodedFormEntity(nameValuePairs,"UTF-8");
httppost.setEntity(form);
HttpResponse response = httpclient.execute(httppost);
InputStream inputStream = response.getEntity().getContent();
Signup.InputStreamToStringExample str = new Signup.InputStreamToStringExample();
responseSignup = str.getStringFromInputStream(inputStream);
Log.e("response", "response -----" + responseSignup);
jsonresponse = new JSONObject(responseSignup);
} catch (Exception e) {
e.printStackTrace();
}
return null;

我在客户端收到“完成”响应,但没有任何行会插入到我的数据库中。任何帮助将不胜感激。

最佳答案

添加

$result->execute();

之后

$result->bind_param("sss",  $mobileUser,$fullnameUser,$usernameUser);

在 php 文件中

关于java - INSERT 查询在 SQL 中有效,但在 Android 应用程序中无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52344465/

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