gpt4 book ai didi

php - 使用 Volley 插入后无法自动递增

转载 作者:行者123 更新时间:2023-11-28 23:16:40 26 4
gpt4 key购买 nike

我正在尝试开发一个 Android 应用程序,我需要在某个时候将数据插入 MySQL 数据库表('demande'),然后检索新记录的自动递增键(demaynde_id),为此我使用了 Volley 库,我注意到插入进行得很顺利,但是当涉及到检索 key 时我无法获取它并且出现了这个错误:W/System.err: org.json.JSONException: 类型为 java.lang.String 的值

这是我的php文件

SendingbookingRequest.php

<?php
require("password.php");
$connect = mysqli_connect("localhost", "XXXXXXXX", "XXXXXXX", "XXXXXXXX");

$driver_id = $_POST["driver_id"];
$email = $_POST["email"];
$adresse_source = $_POST["adresse_source"];
$duree = $_POST["duree"];
$distance = $_POST["distance"];
$response = array();
$dt_obj = new DateTime($response['send_moment'], new
DateTimeZone('America/Chicago'));
$dt_obj->setTimezone(new DateTimeZone('Europe/London'));
$send_time = $dt_obj->format('Y-m-d H:i:s');
echo $send_time;
function AddRequest() {
global $connect, $driver_id, $email, $adresse_source, $duree, $distance, $send_time ;
$statement = mysqli_prepare($connect, "INSERT INTO demande (driver_id, pass_id, adresse_source, duree, distance, send_moment) VALUES (?, (SELECT user_id FROM passager WHERE email = ?),?, ?, ?, ?)");
mysqli_stmt_bind_param($statement, "issdis", $driver_id, $email, $adresse_source, $duree, $distance, $send_time);
mysqli_stmt_execute($statement);

}
function getDemandeId() {
global $connect,$driver_id, $email;
$statement = mysqli_prepare($connect, "SELECT LAST_INSERT_ID() FROM demande WHERE driver_id = ? AND pass_id = (SELECT user_id FROM passager WHERE email = ?)");
mysqli_stmt_bind_param($statement,"is", $driver_id, $email);
mysqli_stmt_execute($statement);
mysqli_stmt_store_result($statement);
mysqli_stmt_bind_result($statement, $demande_id);
while(mysqli_stmt_fetch($statement)){
$response["demande_id"] = $demande_id;


}
}

$response["success"] = false;

AddRequest();
getDemandeId();
$response["success"] = true;


echo json_encode($response);

?>

我尝试删除 getDemandeId(),插入成功,但我在 Android Studio 中遇到了同样的错误。

最佳答案

您检查过回复了吗?格式是否正确 尝试记录您收到的响应并查看其格式是否正确。当您尝试将字符串转换为格式不正确的 jsonObject 时会发生此异常

关于php - 使用 Volley 插入后无法自动递增,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43572164/

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