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.

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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:

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.