0
我一直在試用我的PHP技巧,看起來當我嘗試從我的Android應用程序向PHP發送信息時,它似乎只發送參數名稱(數據庫顯示:作爲例如。)輸出到數據庫。我們使用PDO作爲與MySQL數據庫通信的方式。參數問題
這裏是編碼如下:
$query = "INSERT INTO Customer (Lname, Fname, Address, City, State, ZIP, Phone, myusername, mypassword) VALUES (':Lname', ':Fname', ':Address', ':City', ':State', ':ZIP', ':Phone', ':myusername', ':mypassword')";
//Again, we need to update our tokens with the actual data:
$query_params = array(
':Lname' => $_POST['LName'],
':Fname' => $_POST['FName'],
':Address' => $_POST['Address'],
':City' => $_POST['City'],
':State' => $_POST['State'],
':ZIP' => $_POST['ZIP'],
':Phone' => $_POST['Phone'],
':myusername' => $_POST['username'],
':mypassword' => $_POST['password']
);
//time to run our query, and create the user
try {
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch (PDOException $ex) {
// For testing, you could use a die and message.
//die("Failed to run query: " . $ex->getMessage());
//or just use this use this one:
$response["success"] = 0;
$response["message"] = $ex->getMessage();
die(json_encode($response));
}