Jump to content

[SOLVED] mysql delete on two tables


steveh62

Recommended Posts

I know this might be in the forum somewhere. BUT

 

I have 2 tables that I want to Delete from based on a variable passed in the url...thats done...

 

its just the php mysql structure.

 

on table has different field names to the other yet contains the same data - for reasons known to myself.

 

so, how do I do a Delete on two tables? the code below knocks me out and does nothing

<?php
$sql="delete FROM category, products WHERE category.ID AND products.CATID = '$catid";
    $result = mysql_query($sql);
    echo '<p class="green">Gallery folder and contents deleted!</p>';
?>

Link to comment
https://forums.phpfreaks.com/topic/133209-solved-mysql-delete-on-two-tables/
Share on other sites

I do not think you can do a join delete. I am not sure of this but I think you need 2 seperate statements.

 

<?php
$sql="delete products WHERE products.CATID = $catid";

$sql2="delete category WHERE category.ID = $catid";
?>

 

If you can do it in one blow your SQL is wrong.

 

<?php
$sql="delete category, products WHERE category.ID = $catid AND products.CATID = $catid";
?>

 

You ahve to set it equal to $catid each time.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.