我有这个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";
}
答案 0 :(得分:1)
$query = "INSERT INTO tbl_cars (Car_Model, owner, Car_Type,Capacity,fuelType,carPlatenuNumber,Image) VALUES ('$Car_Model', '$Owner', '$Car_Type',$Capacity,'$fuelType','$carPlatenuNumber','$Image')";
$ carPlatenuNumber应为$ plateNumber
答案 1 :(得分:-1)
使用mysqli_affected_rows ()
mysqli_query($conn, $query);
$result = mysqli_affected_rows ($conn);
它将返回受上一操作影响的行数。