I help my friend with working with databases. It basically has 2 databases, one called the city, and one called the delivery speed. Each table is displayed on a web page with an edit and delete button next to each record. Therefore, it can delete data in the database via the Internet.
The deal is that I want to cascade delete mysql in this database, so that every time I delete a row in the city database, the corresponding row in the delivery speed database with the same city_ID is also deleted. I tried to execute some combination of mysql queries, but that didn't work. Here is what i have
require_once('../../model/city.php'); if(isset($_POST['id'])){ //edit or remove $id = $_POST['id']; $dbo = City::get_by_id($id); if($_POST['action'] == 'remove'){ //remove //$dbo->delete(); mysql_query("DELETE city.*, shipping_rate_loc.* FROM city c, shipping_rate_loc s WHERE c.ID_city = s.ID_city"); echo "Data is removed."; }
As you can see, I just put this mysql_query in my previous
$dbo->delete();
who managed to remove the city, but not associated with the delivery rate.
I am new to using mysql inside PHP, so can anyone help me point out where is my error? Many thanks:)
update: I tried some solutions from the answers. none of them work. even when I simplified things. What makes me wonder if there is any error in terms of connecting php to the database?
gaban source share