Hello guys i have a small isue.. I'm new to PDO and i want to implement it in my website, i have the following code:
foreach($liga1 as $item) {
$data = $item->get_date('j M Y, g:i a');
$titlu = $item->get_title();
$link = $item->get_permalink();
$text = $item->get_description();
$cat = "Liga 1";
$dbhost = "localhost";
$dbname = "site";
$dbuser = "root";
$dbpass = "root";
// database connection
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);
// query
$sql = "INSERT INTO stiri ('id','data', 'continut', 'link', 'titlu', 'categorie' ) VALUES (:data, :text, :link, :titlu, :categorie)";
$q = $conn->prepare($sql);
$q->execute(array(':data', $data,
':continut', $text,
':link', $link,
':titlu', $titlu,
':categorie', $cat));
}
When i run this code i get the following error:
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in C:\xampp\htdocs\ice\sql\sport2.php on line 50
As you can see i want to insert in the database a specific category wich i input, also i have in the mysql table the "id" wich i don't know how to insert it using PDO. I will also want ot use classes here because i need to put the same code on over 20 pages.