我正在研究如何使用angular更新图像并发送后台办公室的http请求(PHP),所以一切正常,它删除旧文件并插入新文件,但问题是这时候来插入数据进入数据库时显示错误。
$rest_json = file_get_contents("php://input");
$_POST = json_decode($rest_json, true);
/*recuperation et affichade de donnée*/
$id = (int)$_REQUEST['id'];
$nom = (string)$_REQUEST['nom'];
$image = $_POST['image'];
echo($id);
echo($nom);
$ok = false;
if (!empty($nom) && !empty($id) && !empty($_FILES["image"]["tmp_name"])) {
/*selectionner et supprimer l'image ancien*/
$query = "SELECT image_ser from etservice WHERE id_service='$id'";
$result = $db->query($query);
if (mysqli_num_rows($result) > 0) {
$res = array();
$res = $result->fetch_all(MYSQLI_ASSOC);
unlink(($res[0]["image_ser"]));
}
/*preparer et inserer la nouvelle image et le nom*/
$filetmp = $_FILES["image"]["tmp_name"];
$tmp_name = $_FILES["image"]["name"];
$filename = md5($tmp_name . time()) . "." . pathinfo($tmp_name, PATHINFO_EXTENSION);
echo($filename);
$filepath = "../assets/img/" . $filename;
move_uploaded_file($filetmp, $filepath);
$query = "UPDATE etservice set nom_service='$nom' AND image_ser='$filepath' WHERE id_service='$id'";
$result = $db->query($query);
if ($result === TRUE) {
$res = "Inserted" . $nom. $id.$filepath;
echo json_encode($res);
} else {
echo json_encode("Error" . $query . "<br>" . $db->error);
}
}
break;
这是我尝试插入一个简单的例子来测试时的错误
ErrorUPDATE etservice set nom_service =&#39; trompita&#39;和 image_ser =&#39; ../资产/ IMG / d67a2bcf47122a855dab0dcfc5926c7d.jpg&#39; WHERE id_service =&#39; 31&#39;
截断错误的DOUBLE值: &#39; trompita&#39;&#34;&#34;
答案 0 :(得分:0)
只需将and语句更改为使用“,”进行查询,以便它变得如此
$query1 = "UPDATE etservice set nom_service='$nom' , image_ser='$filepath' WHERE id_service='$id'";