I stored some products using multiple tables to insert different elements (one table is for title and description, another for images, etc). I know how I can select together everything using inner join by a variable called $codrif, and it works.
But now I have to put a delete option in each product and delete all records in three tables with the same variable $codrif.
I tried this code but it's not working:
Product page:`
...
echo '<td><a href="delete.php?codrif=' . $row['codrif'] . '">Delete</a></td>';
...
delete.php
<?php
// check if the 'codrif' variable is set in URL, and check that it is valid
if (isset($_GET['codrif']))
{
// get codrif value
$codrif = $_GET['codrif'];
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// sql to delete a record
$sql = "DELETE FROM singleimageupload, uploads, exposition
USING exposition
INNER JOIN singleimageupload ON singleimageupload.codrif = exposition.codrif
INNER JOIN uploads ON uploads.codrif = exposition.codrif
WHERE exposition.codrif=$codrif";
if ($conn->query($sql) === TRUE) {
echo "Record deleted successfully";
} else {
echo "Error deleting record: " . $conn->error;
}
}
$conn->close();
?>
Any suggestion?