i am working on how to update image with angular and send http request for the back office (PHP), so everything work fine , it delete the old file and insert the new one but the problem is this when come to insert the data into the database it show me an error.
$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;
and this is the error when i try to insert a simple example to test
ErrorUPDATE etservice set nom_service='trompita' AND image_ser='../assets/img/d67a2bcf47122a855dab0dcfc5926c7d.jpg' WHERE id_service='31'
Truncated incorrect DOUBLE value: 'trompita'""
and this is the database structure
i ll be so grateful if any one help me