使用Volley插入后无法自动增加

时间:2017-04-23 14:06:46

标签: php android mysql android-volley

我正在尝试开发一个Android应用程序,我需要在某个时候将数据插入MySQL数据库表(' demande')然后检索新记录的自动增量key(demaynde_id),为此,我使用了Volley库,我注意到插入过程非常顺利,但是在检索密钥时我无法得到它而且我收到了这个错误: W / System .err:org.json.JSONException:  价值< java.lang.String类型的br不能转换为JSONObject

这是我的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中遇到了同样的错误。

1 个答案:

答案 0 :(得分:1)

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