Error updating PDOException data: SQLSTATE [HY093]

0

I need help, I'm not very good at php, but when I try to verify if this works in POSTMAN he says:

  

Fatal error: Uncaught PDOException: SQLSTATE [HY093]: Invalid   parameter number: number of bound variables does not match number of   tokens in   /storage/ssd4/970/3632970/public_html/ArchivosPHP/login.php:77

     

Stack trace: 0   /storage/ssd4/970/3632970/public_html/ArchivosPHP/login.php(77):   PDOStatement-> execute (Array) 1   /storage/ssd4/970/3632970/public_html/PHP/Archives/Update.php(6):   Registration :: UpdateInformation ('mail @ g ...', 'Name', 'Surnames',   '01', '01', '2017', 'Genre', 'Password') 2 {main} thrown in   /storage/ssd4/970/3632970/public_html/ArchivosPHP/login.php on line 77

This is the method:

public static function ActualizarInformacion($correo,$nombre,$apellidos,$dia,$mes,$anio,$sexo, $contra){
            if(self::ObtenerUsuariosPorId($correo)){
                $consultar = "UPDATE DatosPersonales SET correo = ?, nombre = ?, apellidos = ?, dia = ?,mes = ?,anio = ?,sexo = ? ,contra = ? WHERE correo = ?";
                $resultado = Database::getInstance()->getDb()->prepare($consultar);
                return $resultado->execute(array($correo,$nombre,$apellidos,$dia,$mes,$anio,$sexo,$contra));
            }else{
                return false;
            }
        }

Line 77 is:

return $resultado->execute(array($correo,$nombre,$apellidos,$dia,$mes,$anio,$sexo,$contra));

Here the other php file:

<?php
require 'login.php';

if($_SERVER['REQUEST_METHOD']=='POST'){
    $datos = json_decode(file_get_contents("php://input"),true);
    $respuesta = Registro::ActualizarInformacion($datos["correo"],$datos["nombre"],$datos["apellidos"],$datos["dia"],$datos["mes"],$datos["anio"],$datos["sexo"],$datos["contra"]);
    if($respuesta){
        echo "Se Actualizaron los datos correctamente";
    }else{
        echo "EL usuario no existe";
    }
}

?>
    
asked by Juan Carlos Ruiz 18.01.2018 в 22:34
source

1 answer

0

You have to create a valid array to pass it to the execute , in which there are as many parameters as there are markers in the query. Since you have to pass the mail twice , you can not use position markers ? , but you will have to change them by name markers, in order to differentiate the two parameters you need from correo :

public static function ActualizarInformacion($correo,$nombre,$apellidos,$dia,$mes,$anio,$sexo, $contra){
            if(self::ObtenerUsuariosPorId($correo)){
                $consultar = "UPDATE DatosPersonales SET 
                                correo = :correo, 
                                nombre = :nombre, 
                                apellidos = :apellidos, 
                                dia = :dia, 
                                mes = :mes, 
                                anio = :anio, 
                                sexo = :sexo, 
                                contra = :contra 
                              WHERE correo = :correo_where";
                $resultado = Database::getInstance()->getDb()->prepare($consultar);
                $arrParams=array(
                                    ':correo' => $correo, 
                                    ':nombre' => $nombre, 
                                    ':apellidos' => $apellidos, 
                                    ':dia' => $dia,
                                    ':mes' => $mes,
                                    ':anio' => $anio,
                                    ':sexo' => $sexo,
                                    ':contra' => $contra,
                                    ':correo_where'=>$correo
                                );
                return $resultado->execute($arrParams);
            }else{
                return false;
            }
        }
    
answered by 18.01.2018 в 23:41