Jump to content

DELETE FROM EXISTS ISSUE


brandon000

Recommended Posts

Buddy ol' Pals...please tell me why the following delete statement doesn't work.  I keep getting "Query was empty".  When I run the SQL with the "Select" statement just to verify any results and it works fine but when I set it to DELETE it doesn't work at all. ???

 

if ((isset($_GET['Delete_ProductID'])) && ($_GET['Delete_ProductID'] != "")) {

$DeleteProductID=$_GET['Delete_ProductID'];	

mysql_query("DELETE FROM product_sizes as p WHERE Exists (Select StyleID From product_styles as m Where m.ProductID=".$DeleteProductID." and p.StyleID=m.StyleID)");

}

Link to comment
https://forums.phpfreaks.com/topic/100173-delete-from-exists-issue/
Share on other sites

Well you can query first then run the delete

 

$check = "SELECT StyleID FROM product_styles WHERE ProductID = '$DeleteProductID'";
$ch_res = mysql_query($check) or die(mysql_error());
$found = mysql_num_rows($ch_res);
if($found > 0){
$row = mysql_fetch_assoc($ch_res);
$styleid = $row['StyleID'];
$delete = "DELETE FROM product_sizes WHERE StyleID = '$styleid'";
mysql_query($delete) or die(mysql_error());

 

Hope I interpolated that correctly.

 

Ray

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.