php - Delete from two tables -
i trying delete series of rows database using delete button, data split across 2 tables, joined 1 common field. have created following, delete isn't working right.
$watchlist_id = $_get['id']; // delete watchlist if ($submit == 'delete watchlist') { require_once("db_connect.php"); $deletewatchlist_bad_message = ''; if ($db_server) { $purge_watchlist_query = "delete watchlist_films watchlist_id = '$watchlist_id'"; mysql_query($purge_watchlist_query) or die("delete failed. " . mysql_error() . "<br />" . $purge_watchlist_query); $delete_watchlist_query = "delete watchlists watchlist_id = '$watchlist_id'"; mysql_query($delete_watchlist_query) or die("delete failed. " . mysql_error() . "<br />" . $delete_watchlist_query); } else { $deletewatchlist_bad_message = '<div class="alert alert-error">error: not connect database.</div>'; } require_once("db_close.php");?> <script type="text/javascript"> window.location = "profile.php" </script><?php }
basically, want delete films in watchlist in watchlist_films table ($purge_watchlist_query
), delete watchlist watchlists tables ($delete_watchlist_query
), before redirecting user profile page.
apologies not being clear enough - when 'the delete isn't working right', what's happening when clicking delete button being redirected profile.php, watchlist attempting delete still showing and, when click through it, film contains still there. aren't getting errors or being spat out me, it's not deleting records. hope clarifies!
ok, i've figured out problem.
basically, original element submitting watchlist.php
, rather watchlist.php?id=$watchlist_id
. once i'd amended that, delete worked fine.
Comments
Post a Comment