Jump to content

Delete a row where two columns are equal to variables.


Namtip

Recommended Posts

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.

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));

 

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);

 

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.';

 

:rtfm:

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.