我有这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,而不是数字。 –