我有這insert.php
文件插入數據到我的數據庫,但每次我提交數據$result
總是返回false。我不知道問題出在哪裏,它總是迴應"something error"
。
##Insert.php
include_once("connection.php");
if (
isset($_POST['txtCarModel']) && isset($_POST['txtCarType']) &&
isset($_POST['txtCapacity']) && isset($_POST['image']) &&
isset($_POST['txtFuelType']) && isset($_POST['txtPlateNumber']) &&
isset($_POST['txtOwner'])
) {
$now = DateTime::createFromFormat('U.u', microtime(true));
$id = $now->format('YmdHis');
$upload_folder = "upload";
$path = "ftp://$upload_folder/$id.jpeg";
$image = $_POST['image'];
$fullpath = "carkila.esy.es/$upload_folder/$id.jpeg";
$Car_Model = $_POST['txtCarModel'];
$Car_Type = $_POST['txtCarType'];
$Capacity = $_POST['txtCapacity'];
$Fuel_Type = $_POST['txtFuelType'];
$PlateNumber = $_POST['txtPlateNumber'];
$Image = $_POST['image'];
$Owner = $_POST['txtOwner'];
$query = "INSERT INTO tbl_cars (Car_Model, owner, Car_Type,Capacity,fuelType,carPlatenuNumber,Image) VALUES ('$Car_Model', '$Owner', '$Car_Type',$Capacity,'$fuelType','$carPlatenuNumber','$Image')";
$result = mysqli_query($conn, $query);
if ($result > 0) {
if (isset($_POST['mobile']) && $_POST['mobile'] == "android") {
echo "success";
exit;
}
echo "Insert Successfully";
} else {
if (isset($_POST['mobile']) && $_POST['mobile'] == "android") {
echo "failed";
exit;
}
echo "Something Error";
}
採取的mysqli的預處理語句的優勢,用'mysqli_error'檢查的問題。 – aynber
'mysqli_error()'說什麼?當出現錯誤時結果爲'0',所以你需要找出發生了什麼錯誤。 – VoteyDisciple
請注意,'mysqli_query'通過INSERT查詢返回true或false,而不是數字。 –