Namtip Posted October 12, 2010 Share Posted October 12, 2010 Problem: I've echoed out all the variables and they all come up and the while loop works too but I want to delete a row from a table where the $session and $row['product_code'] variables match. Result: The row does not get deleted. while ($row = mysql_fetch_array($result)) { if (isset($row['product_code']) > 0) { $ans = $row['quantity'] - $row['qty']; if ($ans<= 0) { $query1 = 'DELETE FROM ecomm_temp_cart WHERE session = "' . $session . ' AND product_code = ' . $row['product_code'] . '"'; mysql_query($query, $db) or (mysql_error($db)); echo 'This ' .$row['product_code'] . ' is sold out.'; } } } Any help appreciated. Link to comment https://forums.phpfreaks.com/topic/215656-delete-a-row-where-two-columns-are-equal-to-variables/ Share on other sites More sharing options...
Namtip Posted October 12, 2010 Author Share Posted October 12, 2010 tried the following but still got the same result. 1 $query1 = 'DELETE FROM ecomm_temp_cartWHERE session = "' . $session . '" AND product_code = "' . $row['product_code'] . '"';mysql_query($query, $db) or (mysql_error($db)); 2 $query1 = 'DELETE' . $row . 'FROM ecomm_temp_cartWHERE session = "' . $session . '" AND product_code = "' . $row['product_code'] . '"';mysql_query($query, $db) or (mysql_error($db)); Link to comment https://forums.phpfreaks.com/topic/215656-delete-a-row-where-two-columns-are-equal-to-variables/#findComment-1121299 Share on other sites More sharing options...
Namtip Posted October 12, 2010 Author Share Posted October 12, 2010 Is it possible to delete rows where two variable match? I'm not getting any parse or mysql errors. Here's a bigger part of my script: $query = 'SELECT h.product_code, h.qty, j.product_code, j.quantityFROM ecomm_temp_cart h JOIN ecomm_products j ON h.product_code = j.product_codeWHERE h.session = "' . $session . '"';$result = mysql_query($query, $db) or (mysql_error($db));while ($row = mysql_fetch_array($result)) {if (isset($row['product_code']) > 0) {$ans = $row['quantity'] - $row['qty'];if ($ans<= 0) {$query1 = 'DELETE FROM ecomm_temp_cartWHERE session = "' . $session . '" AND product_code = "' . $row['product_code'] . '"';mysql_query($query, $db) or (mysql_error($db));echo $session;echo 'This ' .$row['product_code'] . ' is sold out.';}}}mysql_free_result($result); Link to comment https://forums.phpfreaks.com/topic/215656-delete-a-row-where-two-columns-are-equal-to-variables/#findComment-1121325 Share on other sites More sharing options...
Namtip Posted October 12, 2010 Author Share Posted October 12, 2010 Don't mind me, I treat this place more as a notepad to work things out is that bad? - here's the code that works: if ($ans<= 0) {$query1 = 'DELETE FROM ecomm_temp_cartWHERE session = "' . $session . '" AND product_code = "' . $row['product_code'] . '"';mysql_query($query1, $db) or (mysql_error($db));echo 'This ' .$row['product_code'] . ' is sold out.'; Link to comment https://forums.phpfreaks.com/topic/215656-delete-a-row-where-two-columns-are-equal-to-variables/#findComment-1121329 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.