Reputation: 759
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
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