I'm trying to delete from multiple tables at once using the JOIN but if for any reason the contacts table does not have any data for the user (applebottomjeans) the code below doesn't run correctly. Nothing gets deleted/removed. I get no error.
How do would fix this to maybe ignore that and to just delete the accounts table data and the subscriptions table data? Am I missing something here?
$user = $_GET['user_name'); // Username: applebottomjeans
// Delete user from records in accounts table, subscriptions table and contacts table
$sql = "DELETE FROM accounts, subscriptions, contacts
USING accounts JOIN subscriptions JOIN contacts
WHERE accounts.username = '$user' AND subscriptions.user_id = '$user'
AND contacts.username = '$user' ";
if ($conn->query($sql) === TRUE) {
echo "The users data was removed from our end.";
} else {
echo "Error deleting user from our records. " . $conn->error;
}