We help IT Professionals succeed at work.

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

Chadd C
Chadd C asked
on
992 Views
Last Modified: 2014-08-02
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

Comment
Watch Question

CERTIFIED EXPERT
Expert of the Year 2014
Top Expert 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Chadd CSolutions Guy

Author

Commented:
Thanks, Gary!  Exceptional advice as always!
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.