Search code examples
phpmysqlmysqliprepared-statementbindvalue

prepared statement help, 63/63 parameters failing with number of parameters mismatch


i'm having troubles with my prepared statement (mysqli), i'm doing my connection and everything's right until i try to bind parameters, here's the problem, i'ml trying to bind 63 values, and I did check many times i have the right amout of values and feel desperate because i' can't find the mistake leading me to the error :

mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement

Here follow my code:

$query = $db->prepare("INSERT INTO `T_TOUR_RES`(`Id`, `UpDate`, `NumVoie`, `Indice`, `Voie`, `Ville`, `CodePostal`, `LocNom`, `LocPrenom`, `LocNumVoie`, `LocIndice`, `LocVoie`, `LocCodePostal`, `LocVille`, `LocTel`, `PropNom`, `PropPrenom`, `PropNumVoie`, `PropIndice`, `PropVoie`, `PropVille`, `PropCodePostal`, `PropTel`, `EntRaisonSociale`, `EntDenominationCommerciale`, `EntTypeEntreprise`, `EntNumVoie`, `EntIndice`, `EntVoie`, `EntVille`, `EntCodePostal`, `EntTel`, `EntAPE`, `EntNAF`, `EntSIRET`, `IsLoc`, `IsProp`, `IsPro`, `IsAdmin`, `Done`, `DoneDate`, `DoneEq`, `IsIndiv`, `IsCollectif`, `NbOccupants`, `HasComposteur`, `IsPrincipal`, `IsSecondaire`, `IsGite`, `IsHote`, `IsRefus`, `IsWeb`, `HasPlace`, `IsDiffManip`, `IsPrecoPAV`, `LinkCollectif`, `IsBatimentCollectif`, `HaveBac`, `NbOM`, `NbTri`, `Comportement`, `Remarque`, `RecapBac`, `ID_TOUR`, `ID_SOURCE`) VALUES (NULL, NOW(),'?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?')");

    if ($query === FALSE) {
        die ("Mysql Error: " . $db->error);
    } else {
        if ($query->bind_param("issssssisssssssissssssssissssssssiiiiissiiiiiiiiiiiiiiiiiisssii",$this->NumVoie, $this->Indice, $this->Voie, $this->Ville, $this->CodePostal, $this->LocNom, $this->LocPrenom, $this->LocNumVoie, $this->LocIndice, $this->LocVoie, $this->LocCodePostal, $this->LocVille, $this->LocTel, $this->PropNom, $this->PropPrenom, $this->PropNumVoie, $this->PropIndice, $this->PropVoie, $this->PropVille, $this->PropCodePostal, $this->PropTel, $this->EntRaisonSociale, $this->EntDenominationCommerciale, $this->EntTypeEntreprise, $this->EntNumVoie, $this->EntIndice, $this->EntVoie, $this->EntVille, $this->EntCodePostal, $this->EntTel, $this->EntAPE, $this->EntNAF, $this->EntSIRET, $this->IsLoc, $this->IsProp, $this->IsPro, $this->IsAdmin, $this->done, $this->DoneDate, $this->DoneEq, $this->IsIndiv, $this->IsCollectif, $this->NbOccupants, $this->HasComposteur, $this->IsPrincipal, $this->IsSecondaire, $this->IsGite, $this->IsHote, $this->IsRefus, $this->IsWeb, $this->HasPlace, $this->IsDiffManip, $this->IsPrecoPAV, $this->LinkCollectif, $this->IsBatimentCollectif, $this->HaveBac, $this->NbOM, $this->NbTri, $this->Comportement, $this->Remarque, $this->RecapBac, $this->ID_TOUR, $this->ID_SOURCE)) {

            if($query->execute()){}else{die ("Mysql Error: " . $db->error);}
        } else { 
            die ("Mysql Error: " . $db->error);
        }
    }

Hoping someone can explain me what i'm failing here !


Solution

  • You if you're using prepared statements you should not use single-quotes around your ?

    $query = $db->prepare("INSERT INTO `T_TOUR_RES`(`Id`, `UpDate`, `NumVoie`, `Indice`, `Voie`, `Ville`, `CodePostal`, `LocNom`, `LocPrenom`, `LocNumVoie`, `LocIndice`, `LocVoie`, `LocCodePostal`, `LocVille`, `LocTel`, `PropNom`, `PropPrenom`, `PropNumVoie`, `PropIndice`, `PropVoie`, `PropVille`, `PropCodePostal`, `PropTel`, `EntRaisonSociale`, `EntDenominationCommerciale`, `EntTypeEntreprise`, `EntNumVoie`, `EntIndice`, `EntVoie`, `EntVille`, `EntCodePostal`, `EntTel`, `EntAPE`, `EntNAF`, `EntSIRET`, `IsLoc`, `IsProp`, `IsPro`, `IsAdmin`, `Done`, `DoneDate`, `DoneEq`, `IsIndiv`, `IsCollectif`, `NbOccupants`, `HasComposteur`, `IsPrincipal`, `IsSecondaire`, `IsGite`, `IsHote`, `IsRefus`, `IsWeb`, `HasPlace`, `IsDiffManip`, `IsPrecoPAV`, `LinkCollectif`, `IsBatimentCollectif`, `HaveBac`, `NbOM`, `NbTri`, `Comportement`, `Remarque`, `RecapBac`, `ID_TOUR`, `ID_SOURCE`) VALUES (NULL, NOW(),?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
    

    Edit:
    Next time maybe make 1 google search on the error:
    Php mysqi bind_param Number of variables doesn't match number of parameters in prepared statement