2

The following code runs without any errors but doesn't actually delete anything:

      $update = $mysqli->prepare('DELETE FROM table WHERE RetailerID = ? AND Amount = ? AND FXRate = ?');
      $update->bind_param('iii', $rID, $base_value, $fx_rate);
      $update->execute();
      $update->close();

I have numerous mysqli prepared statments in this same file that execute fine, but this one is the only one that doesn't modify the table. No errors or shown, but the row isn't deleted from the table either. I have verified that $rID, $base_value, and $fx_rate are the correct values, and a row is DEFINITELY present in table that matches those values.

The only difference between this statement and the others are the parameters and the fact that it's DELETE instead of SELECT or UPDATE. I also tried doing a SELECT or UPDATE instead of DELETE using the same WHERE parameters, but no luck. The issue seems to be that it's not finding a row that fits the WHERE parameters, but like I said, the row is definitely there.

Any ideas?

Stone
  • 121
  • 5
  • 14
  • 3
    Have you checked the error codes from the database to see if there's anything there? You could also try running the SQL directly against the database to see if that generates an error - you might not have DELETE permissions, for example. – andrewsi Jun 20 '12 at 00:52
  • Do you have a table called table, or did you just do that for the example you gave? – bumperbox Jun 20 '12 at 00:53
  • like andrewsi said, it could very easily be that the user your code is using might not have delete permissions. Also, check you logs and run the query in phpMyAdmin, if you are using that. – JT Smith Jun 20 '12 at 01:00
  • @andrewsi - Permissions definitely weren't the issue (forgot to state that in my initial question). – Stone Jun 20 '12 at 13:50

1 Answers1

0

Is amount an integer or a double? You're converting to integer ('iii'), but I presume it'll be $0.34 or similar. Try 'idi' instead.

Edit: same applies for rate - is that an integer or double too?

Robbie
  • 17,605
  • 4
  • 35
  • 72
  • Thanks, that was the issue, though my particular case was a bit more complicated. Basically, I was using $base_value across 2 tables, but in one it was stored as a decimal and in the other it was stored as a varchar. So by the time I executed the DELETE statement seen above, $base_value had the decimal removed and thus did not find the matching row in which $base_value had the decimal attached. Not sure why it was setup like that (I didn't create the tables), but I was able to work around it. Thanks! – Stone Jun 20 '12 at 13:47