-2

I get the error:

SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters

when I try to run the following code:

     public function getScore($matchID,$setone,$settwo,$getChallengerScore,$getOpponentScore,$fileOpponentData,$fileChallengerData)
{
   try
   {
       $stmt = $this->db->prepare("UPDATE matches SET `winner` = $setone 
                                        AND `looser` = $settwo 
                                        AND `winner_score` = $getChallengerScore 
                                        AND `looser_score` = $getOpponentScore 
                                        AND `opponent_blob` = '".$fileOpponentData."' 
                                        AND `challenger_blob` = '".$fileChallengerData."' 
                                   WHERE `id` = $matchID");
       #var_dump($stmt);
       $stmt->execute(); 

       return $stmt; 
   }
   catch(PDOException $e)
   {
       echo $e->getMessage();
   }    
} 

I'm not great with PDO, haven't had many issues but this I cannot solve on my own. Any help would be much appreciated.

Sᴀᴍ Onᴇᴌᴀ
  • 8,218
  • 8
  • 36
  • 58
Xamber
  • 3
  • 2

1 Answers1

0

Use a properly parametrized query. And the assignments in an UPDATE statement must be separated by ,, not AND.

$stmt = $this->db->prepare("UPDATE matches SET `winner` = :setone 
                            , `looser` = :settwo 
                            , `winner_score` = :getChallengerScore 
                            , `looser_score` = :getOpponentScore 
                            , `opponent_blob` = :fileOpponentData
                            , `challenger_blob` = :fileChallengerData
                            WHERE `id` = :matchID");
$stmt->execute(array(
    ':setone' => $setone,
    ':settwo' => $settwo,
    ':getChallengerScore' => $getChallengerScore,
    ':getOpponentScore' => $getOpponentScore,
    ':fileOpponentData' => $fileOpponentData,
    ':fileChallengerData' => $fileChallengerData,
    ':matchID' => $matchID
));
Barmar
  • 741,623
  • 53
  • 500
  • 612