Ashish
Ashish

Reputation: 759

PHP PDO Invalid parameter number: parameter was not defined

This is my code :

It gives no error when i change the array to index type instead of associative. But the moment i change it back to associative it starts giving error. Any help on this ?

$dbh=new PDO("mysql:host=localhost;dbname=sj_db", 'root', '');

$entryData = array(
    "Team Name"=>$_POST['name']
  , "Won"=>$_POST['w']
  , "Lost"=>$_POST['l']
  , "Draw"=>$_POST['d']
  , "Points"=>$_POST['p']
  );


$sql="INSERT INTO fb (`Team Name`, Won, Lost, Draw, Points) VALUES (?, ?, ?, ?, ?)";
$sth=$dbh->prepare($sql);
//$sth->execute($entryData[`Team Name`],$entryData['Won'],$entryData['Lost'],$entryData['Draw']
//  ,$entryData['Points']);
$sth->execute($entryData);

//$sth->closeCursor();

Upvotes: 0

Views: 101

Answers (1)

Your Common Sense
Your Common Sense

Reputation: 157886

Placeholders in your query are positional (?) ones.
Either change them to named (:name)
or pass array_values($entryData) into execute

Though you have to remove a space from Team Name key in order to use named placeholders

Upvotes: 1

Related Questions