Skip to content
Advertisement

Uncaught PDOException: SQLSTATE[HY093] [closed]

I get this erro: Invalid parameter number: number of bound variables does not match number of tokens in C:xampphtdocsPHPtennisronde2-wijziging.php:59

// code van het knop wijzigen
if(isset($_POST['wijzig'])){
    $id = $_POST['id'];
    $speler1  = $_POST['speler1'];
    $speler2  = $_POST['speler2'];
    $uitslag1 = $_POST['uitslag1'];
    $uitslag2 = $_POST['uitslag2'];
    $datum    = $_POST['datum'];
    $veld     = $_POST['veld'];

    //UPDATE: gegevens in de form wijzigen.
    $sql = "UPDATE ronde1 SET speler1 = :speler1, speler2 = :speler2, uitslag1 = :uitslag1,
    uitslag2= :uitslag2, datum= :datum, veld= :veld WHERE id=:id";
    $stmt = $pdoConnect->prepare($sql); //stuur naar mysql.
    $stmt->bindParam(":id", $id );
    $stmt->bindParam(":speler1", $speler1 );
    $stmt->bindParam(":speler1", $speler1 );
    $stmt->bindParam(":uitslag1", $uitslag1 );
    $stmt->bindParam(":uitslag2", $uitslag2 );
    $stmt->bindParam(":datum", $datum );
    $stmt->bindParam(":veld", $veld );
    $stmt->execute();

    // $_SESSION['message'] = "Speler is gewijzigd";
    // $_SESSION['msg_type'] = "warning";
    header("location: #.php");
    exit;
}

I want to update my data.strong text

Advertisement

Answer

My solution worked but didn’t explain why it did go wrong in the first place. The user dpant explains in the comments why your code snippet was not working.

Credits go to him

dpant:

Most probably the problem with your original code was that you were binding the :speler1 parameter twice (the :speler2 parameter was never bound). This was just a typo in your code. Take a close look at it.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement