I'm helping my friend in doing some database management stuff. Basically he has 2 databases, one is called city and one is called shipping rate. Each tables are displayed in a web page with edit and remove button beside each record. So he can delete the data in database via web.
The deal is, I want to do a cascade delete on this mysql database, so that every time I delete a row in city database, a corresponding row in shipping rate database with the same city_ID is deleted as well. I tried to do some mysql query combination, but it didn't work. Here's what I've got
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'm just putting that mysql_query on his previous
$dbo->delete();
code which managed to delete the city, but not its related shipping rate.
I'm fairly novice in using mysql inside PHP, so can anybody help me pointing out where my mistake is? Thank you very much :)
update: I've tried some solutions from the answers. none of them working. even when I simplified things. Which makes me wonder, is there any mistake in terms of connecting the php to the database?