2

I get

Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined

when trying to run the following code, both with bindValue and bindParam yet can't seem to see what is wrong.

class Product {

    public function productAdd($x) {
        $core = Core::getInstance(); // This part works OK
        $stmt = $core->dbh->prepare('INSERT INTO Product (Product_Name) VALUES (:product-name)');
        $stmt->bindValue(':product-name', $x, PDO::PARAM_STR);
        $stmt->execute();
    }

}

$product = new Product;
$productadd = $product->productAdd('Blue Sunglasses');
2
  • 3
    I wonder if it's because of the -. Try without that, like :productName Commented Jun 12, 2013 at 15:30
  • OMG ? Duh, yup, that did it. Thanks!!! Can't believe that. It took me hours!!! Fresh eyes are always welcomed. Commented Jun 12, 2013 at 15:37

1 Answer 1

4

named parameters must be one of these:

BINDCHR     = [:][a-zA-Z0-9_]+;

change the hyphen to an underscore or remove it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.