1
我正在嘗試開發一個android應用程序,並且我需要某些時候將數據插入到MySQL數據庫表('demande'),然後檢索新記錄的自動增量鍵(demaynde_id),爲此我使用了Volley庫,我已經注意到插入過程很順利,但是當涉及到檢索密鑰時,我無法得到它,並且出現此錯誤:W/System.err:org。 json.JSONException: 值< java.lang.String類型的BR不能轉換爲JSONObject的使用Volley插入後無法獲得自動增量
這是我的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中得到了同樣的錯誤。
我試過了,但是我做不到,只是因爲當我試圖替換'?'時,與真正的價值,我不得不從function2中刪除變量,並給我一個錯誤:錯誤的參數計數爲mysqli_stmt_bind_param()在/storage/h3/744/754744/public_html/SendBookingReq.php 26行 –
使用echo json_encode發送數據? –
如果這是一個問題,我的答案是肯定的,我確實使用它並且它工作 –