Link to home
Start Free TrialLog in
Avatar of Chadd C
Chadd C

asked on

Using PhP/MySQL, how can I delete records from two tables with a common user_id

I'm trying to delete all records (by user_id) from two tables. Below is my script. It's not generating errors but its also not deleting records.  Hopefully someone can lend some clarity!

// Get the user ID of the user to delete
$user_id = $_GET['user_id'];

// Build the DELETE statement
				
$delete_query = sprintf("DELETE FROM users t1 INNER JOIN user_training_items t2 ON t1.user_id=t2.user_id WHERE t1.user_id= %d",
$user_id);

// Delete the user from the database
mysql_query($delete_query);

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Chadd C
Chadd C

ASKER

Thanks, Gary!  Exceptional advice as always!