Reputation: 15
No error is showing, but for some reason I cannot add new entries when I run this script. Any help would be appreciated.
$sth = $dbh->prepare('INSERT INTO inventory(sku, product-id, product-id-type, price, minimum-seller-allowed-price, maximum-seller-allowed-price, item-condition, quantity, add-delete, will-ship-internationally, expedited-shipping, item-note, fulfillment-center-id)
VALUES(:sku, :product_id, :product_id_type, :price, :minimum, :maximum, :condition, :quantity, :add_delete, :international, :expedited, :note, :fulfillment)');
$sth->bindParam(':sku', $sku);
$sth->bindParam(':product_id', $product_id);
$sth->bindParam(':product_id_type', $product_id_type);
$sth->bindParam(':price', $price);
$sth->bindParam(':minimum', $minimum);
$sth->bindParam(':maximum', $maximum);
$sth->bindParam(':condition', $condition);
$sth->bindParam(':quantity', $quantity);
$sth->bindParam(':add_delete', $add_delete);
$sth->bindParam(':international', $international);
$sth->bindParam(':expedited', $expedited);
$sth->bindParam(':note', $note);
$sth->bindParam(':fulfillment', $fulfillment);
$sth->execute();
Upvotes: 1
Views: 34
Reputation: 74217
"No error is showing..."
No errors? Because, you're not checking for them. Many of your columns contain hyphens and MySQL thinks you want to do math.
I.e.: product-id
which MySQL translates as "product minus id" etc.
setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION)
would have signaled the syntax errors.
Wrap all your columns that contains hyphens with ticks.
(sku, `product-id`, `product-id-type` ...
etc.
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
right after the connection is opened.Nota:
Upvotes: 2
Reputation: 948
Added here because i can't code it properly in a comment. This is not an answer to the question but i suspect will lead directly to it.
Alter your code like this.
try {
// All $sth lines above in this section.
} catch (PDOException $e) {
// this will print an exception out if there is one.
echo $e->getMessage();
}
Upvotes: 0