I am trying to write a simply query that will delete an event based off its event_id. That event_id could be in 1 of 3 tables in a database however.
Leagues
Tournaments
Trainings
Each event_id is generated by a randomizer function so each id is unique.
I have tried a few different syntaxs for SQL but none of them will actually delete the event from the DB table. Any suggestions?
Here is what I have:
if(isset($_POST['delete'])){
$query = "delete from leagues where event_id= '$event_id', delete from tournaments where event_id= '$event_id', delete from trainings where event_id= '$event_id'";
$result = mysqli_query($conn, $query);
header('location: index_admin.php');
} else {
}
I have also tried using the union command, using multiple delete queries, putting a semicolon after each delete command. What else can I try?
2
Answers
No reason to execute 3 separate DELETEs.
Of course you’d not insert the value into the query like above – you’d use prepared statement.