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

标签 php android mysql android-volley

我正在尝试开发一个 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/

相关文章:

android - Android 11(R) 中的权限被拒绝问题

java - 表未映射的 Hibernate 消息

android - 使用另一个布局创建进度对话框

java - 以类似于 Doodle Jump 和 Cut the Rope 的方式增加分数

php - 使用 Laravel 和 AngularJs

PHP 和 MySQL 设计 map 搜索站点

java - 如何构造 SQL 语句以避免过多的连接

php - 如何限制功能并包含php脚本可以运行?

php - 如何在 soapServer 响应中返回自定义 XML 响应?

php - 使用 php 更新 joomla 配置文件