Bradley Scott
Bradley Scott

Reputation: 53

Query returning false

I have been stuck on this for the past 2 hours and can't see what the problem is here.

When I execute the SQL in phpmyadmin manually it runs fine when i substitute :item_quant and :item_code for their true values.

When adding an echo on return false to see if $item_quant and $item_code are the correct values it shows them as the correct values.

$sql = "UPDATE inventory SET item_quant=item_quant+:item_quant WHERE item_code=':item_code' LIMIT 1";
    $query = $database->prepare($sql);
    $result = $query->execute(array(':item_quant' => $item_quant, ':item_code' => $item_code));

    if ($result) {
        return true;
    }
    return false;

Any help or insight as to why this would be failing would be greatly appreciated.

Upvotes: 2

Views: 65

Answers (2)

Frog82
Frog82

Reputation: 464

Try removing the quotations:

$sql = "UPDATE inventory SET item_quant=item_quant+:item_quant WHERE item_code=:item_code LIMIT 1";

Upvotes: 0

Barmar
Barmar

Reputation: 780688

Placeholders must not be put inside quotes.

$sql = "UPDATE inventory SET item_quant=item_quant+:item_quant WHERE item_code=:item_code LIMIT 1";

Upvotes: 2

Related Questions