• PHP Help
  • Parameters error and call to function Boolean error

I'm trying to inset some data, it's worked before but not now? I'm not sure what I'm doing wrong this time me error messages are:

Warning: PDO::prepare() expects parameter 2 to be array, string given in C:\Apache24\htdocs\portfolio\colours\classes\Data.php on line 16

Fatal error: Uncaught Error: Call to a member function execute() on boolean in C:\Apache24\htdocs\portfolio\colours\classes\Data.php:17 Stack trace: #0 C:\Apache24\htdocs\portfolio\colours\testing.php(19): Data->addScore(30, 'Test') #1 {main} thrown in C:\Apache24\htdocs\portfolio\colours\classes\Data.php on line 17

My code:

Data class:

<?php 
class Data{
	
public function __construct()
{
    $db = $db = new Database;
    $db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_WARNING);
    $this->db = $db;
}


function addScore($totalScore, $name){
	$this->db->beginTransaction();
	$insert = $this->db->prepare('INSERT INTO scores (totalScore, name)
		VALUES
		(:totalScore', ':name');	
	$insert->execute(array(
	':totalScore' => $totalScore,
	':name' => $name
	));
	$this->db->commit();
}

}

calling the class ect.

<?php 

require('classes/Database.php');
require('classes/Data.php');

$db = new Database;

$post = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);	
$totalScore = 30;
$name = "Test";
//	= $name = $totalScore = $score = $wrong = "";
	$scores = "SELECT totalScore FROM gamescore WHERE totalScore < :totalScore";  
$stmt = $db->prepare($scores);
$stmt->bindValue(':totalScore', $totalScore); $stmt->execute(); $counts = $stmt->rowCount(); if($counts < 20){ $addScore = new Data(); $addScore->addScore($totalScore, $name); }
    Write a Reply...