-4

i have this code

switch ($var1) {
case 'corredor':{
  $query = '  UPDATE corredor   
              SET 
                      cedula = :cedula,
                      nombres = :nombres,
                      apellidos = :apellidos,
                      fechanacimiento = :fechanacimiento,
                      telefono = :telefono,
                      correo = :correo,
                      direccion = :direccion,
                      fecharegistro = :fecharegistro,
                      estatus = :estatus,
                      aseguradora_rif =: aseguradora_rif
               WHERE cedula = :cedula_old
            ';
    $query_params = array(
        ':cedula' => $_POST['cedula'],
        ':nombres' => $_POST['nombres'],
        ':apellidos' => $_POST['apellidos'],
        ':fechanacimiento' => $_POST['fechanacimiento'],
        ':telefono' => $_POST['telefono'],
        ':correo' => $_POST['correo'],
        ':direccion' => $_POST['direccion'],
        ':fecharegistro' => $_POST['fecharegistro'],
        ':estatus' => $_POST['estatus'],
        ':aseguradora_rif' => $_POST['aseguradora_rif']
        ':cedula_old' => $var2
        );
    try {
        $stmt = $db->prepare($query);

        $result = $stmt->execute($query_params);
    } catch (PDOException $ex) {
        $ex->getMessage();
    }
    #header('Location: index.php?do=listacorredor');
    break;
} //fin case

i'm getting

SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens

and i don't know why, all my parameters seems to match, i already looked for extra , at the end of the query and params all the binds match the database names so i'm lost here, the other answers were things like missing , or something like that but really can't see the problem here.

1 Answers1

-1

you forgot bind params :)

http://php.net/manual/es/pdostatement.bindparam.php

http://php.net/manual/es/pdostatement.bindvalue.php

Before execute(), you need "assign" values to correspond data into array.

Ex:

$stmt = $db->prepare($query);

$stmt->bindParam(':cedula', $_POST['cedula']);

$result = $stmt->execute();
elporfirio
  • 306
  • 2
  • 15