This script is working for deleting from mysql database, but it’s not unlinking from local directory files. Can anyone help to fix this script? Here’s the script. The rows is:
| product_id | product_image |
| ---------- | ---------------------------------- |
| 161 | ../up/3100882396654337b6a6da.png |
The PHP:
<?php
require_once 'database.php';
$valid['success'] = array('success' => false, 'messages' => array());
$productId = $_POST['productId'];
if($productId) {
$sql = "DELETE FROM product WHERE product_id = {$productId}";
if($connect->query($sql) === TRUE) {
$valid['success'] = true;
$valid['messages'] = "Successfully deleted";
} else {
$valid['success'] = false;
$valid['messages'] = "Error could not be deleted";
}
$connect->close();
echo json_encode($valid);
}
New contributor
Juan Carlos Bringas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1