It seems to me that everything is going OK, but when it makes the statement it gives me the following error:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: parameter was not defined' in /Applications/XAMPP/xamppfiles/htdocs/APP2/include/crud_usuario.php:119 Stack trace: #0 / Applications/XAMPP/xamppfiles/htdocs/APP2/include/crud_user.php(119): PDOStatement->execute() #1 /Applications/XAMPP/xamppfiles/htdocs/APP2/include/admin_user.php(42): CrudUsuario-> update(Object(User)) #2 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/APP2/include/crud_user.php on line 119
public function actualizar($usuario){
$db = BaseDatos::conectar();
$actualizar = $db->prepare('UPDATE Usuario SET usuario=:usuario,contrasena=:contrasena,nombre=:nombre,apellido=:apellido,dni=:dni,email=:email,telefono=:telefono,direccion=:direccion,cod_postal=:cod_postal,fecha_nac=:fecha_nac,curso=:cruso,foto=:foto,estado=:estado,tipo=:tipo WHERE id_usuario=:id_usuario');
$actualizar->bindValue(':id_usuario', NULL);
$actualizar->bindValue(':nombre',$usuario->getNombre());
$actualizar->bindValue(':apellido',$usuario->getApellido());
$actualizar->bindValue(':dni',$usuario->getDni());
$actualizar->bindValue(':usuario',$usuario->getUsuario());
$actualizar->bindValue(':contrasena',$usuario->getContrasena());
$actualizar->bindValue(':email',$usuario->getEmail());
$actualizar->bindValue(':telefono',$usuario->getTel());
$actualizar->bindValue(':direccion',$usuario->getDireccion());
$actualizar->bindValue(':cod_postal',$usuario->getCodPostal());
$actualizar->bindValue(':fecha_nac',$usuario->getFechaNac());
$actualizar->bindValue(':curso',$usuario->getCurso());
$actualizar->bindValue(':foto',$usuario->getFoto());
$actualizar->bindValue(':estado',$usuario->getEstado());
$actualizar->bindValue(':tipo',$usuario->getTipo());
$actualizar->execute();
}
The problem you are experiencing is that you are using a named placeholder in the SQL
:cruso
butcurso=:cruso
then assigning a value to the placeholder:curso
in thebindValue
.When executing the PDO query, it generates an exception because MySQL does not find values for all the markers, that is why the error message appears:
In Spanish:
Ideally, it would
bindValue
be the one to detect the inconsistencies, but unfortunately this is not the case and that is why this is a very common error.I have fixed your code so that the correct name is displayed in the SQL: