我有問題將數據插入到我的數據庫中。數據無法插入,並且在我的Logcat中不顯示任何錯誤。我正在努力,但仍然無法解決問題。這是我的PHP代碼:將數據插入服務器
<?php
require ("config1.php");
if(!empty($_POST)){
$query = "SELECT * FROM announcement WHERE announceID = :announcementID";
$query_params=array(':announcementID'=> $_POST['announcementID']);
try{
$stmt=$db->prepare($query);
$stmt->execute($query_params);
}catch(PDOException $ex){
$response["success"]=0;
$response["message"]="Database Error1. Please try again";
die(json_encode($response));
}
$row = $stmt->fetch();
if($row){
$query = "INSERT INTO announcement (title,description,start_date,end_date,time)
VALUES (:title,:description,:starDate,:endDate,:time) ";
$query_params= array(
':title'=>$_POST['title'];
':description'=>$_POST['description'];
':startDate' => $_POST['start_date'];
':endDate' => $_POST['end_date'];
':time' => $_POST['time'];
);
try {
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch (PDOException $ex) {
$response["success"] = 0;
$response["message"] = "Database Error2. Please Try Again!";
die(json_encode($response));
}
$response["success"] = 1;
$response["message"] = "Update successful!";
echo json_encode($response)
}
}
?>
下面是我的Java代碼:
protected String doInBackground(Void... params) {
RequestHandler rh=new RequestHandler();
HashMap<String,String> param= new HashMap<String, String>();
param.put(KEY_TITLE,announcement_title);
param.put(KEY_DESCRIPTION,announcement_desc);
param.put(KEY_START_DATE,start_date);
param.put(KEY_END_DATE,end_date);
param.put(KEY_TIME,time);
param.put(KEY_IMAGE,announcement_image);
String result= rh.sendPostRequest(ANNOUNCEMENT_URL,param);
return result;
}
欣賞的是有人能指出問題。
我無法找到你要發送'announcementID'的地方 - 所以我敢打賭一個未定義的索引錯誤,可能會被壓制。 - >確保error_reporting()已打開! – Jeff