I'm creating an ADD/UPDATE/DELETE system for my database, and while coding the delete query I've found a constraint fails, preventing me from deleting certain data from a specific row.
Delete query:
if (isset($_GET['company'])) {
$id = $_GET['company'];
$query_del = " DELETE company.* , client.* , queries.*
FROM company
INNER JOIN client ON company.idcompany =
client.idcompany
INNER JOIN queries ON
client.idclient =
queries.idclient
WHERE company.idcompany = '" . $id . "'";
$result_del = mysqli_query($con, $query_del);
if ($result_del) {
header("location:companylist.php");
} else {
echo ' Erro: ' . mysqli_error($con);
}
}
Tables required:
company: idcompany , company_name
client: idclient , idcompany
queries: idclient
Error:
Cannot delete or update a parent row: a foreign key constraint fails (
db.client, CONSTRAINTclient_ibfk_1FOREIGN KEY (idcompany) REFERENCEScompany(idcompany))
Basically, I'm getting the row number through URL and trying to delete all the data related with that idcompany on all three tables. Does somebody know how I can relate all three tables on a delete query?