IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

PHP & Base de données Discussion :

Erreur Type : Unsupported operand types


Sujet :

PHP & Base de données

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2017
    Messages
    95
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 25
    Localisation : France, Loiret (Centre)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2017
    Messages : 95
    Par défaut Erreur Type : Unsupported operand types
    Bonjour,

    Je me permets de demander de l'aide concernant l'erreur suivante :
    Fatal error: Uncaught Error: Unsupported operand types in C:\wamp64\www\public_html\PPE 3.2\PPE3.2 - IFRA EN COURS\controleur\controleurInscription.php on line 37
    Tip : La ligne 37 correspond à : $utilisateur->setIdIntervenant(IntervenantDAO::maxID()+1); dans le controleurInscription().

    Ci - dessous, vous trouverez les fichiers qui sont concernés (je suis le modèle MVC)

    Le controleurInscription :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    <?php
    require_once 'fonctions/formulaire.php';
     
    	$formInscription = new Formulaire("post","index.php","formInscription","formInscription");
            $formInscription->ajouterComposantLigne($formInscription->creerTitreH3("Créer un utilisateur"));
            $formInscription->ajouterComposantTab();
            $formInscription->ajouterComposantLigne($formInscription->creerLabelFor("nom", "Nom  : "));
            $formInscription->ajouterComposantLigne($formInscription->creerInputTexte("nom", "nom", "", "" ,""  , "" , ""));
            $formInscription->ajouterComposantTab();
            $formInscription->ajouterComposantLigne($formInscription->creerLabelFor("prenom", "Prénom : "));
            $formInscription->ajouterComposantLigne($formInscription->creerInputTexte("prenom", "prenom", "", "" ,""  , "" , ""));
            $formInscription->ajouterComposantTab();
     
            $formInscription->ajouterComposantLigne($formInscription->creerLabelFor("codeS", "Statut : "));
            $formInscription->ajouterComposantLigne($formInscription->creerInputTexte("codeS", "codeS", "", "" ,""  , "" , ""));
            $formInscription->ajouterComposantTab();
            $formInscription->ajouterComposantLigne($formInscription->creerLabelFor("nomUtilisateur", "Nom d'utilisateur : "));
            $formInscription->ajouterComposantLigne($formInscription->creerInputTexte("nomUtilisateur", "nomUtilisateur", "", "" ,""  , "" , ""));
            $formInscription->ajouterComposantTab();
            $formInscription->ajouterComposantTab();
            $formInscription->ajouterComposantLigne($formInscription->creerLabelFor("mdp", "mot de passe : "));
            $formInscription->ajouterComposantLigne($formInscription->creerInputMdp("mdp", "mdp", "","","","",""));
            $formInscription->ajouterComposantTab();
     
            $formInscription->ajouterComposantLigne($formInscription->creerInputSubmit("enregistrer", "enregistrer", "Enregistrer"));
            $formInscription->ajouterComposantTab();
     
            $formInscription->creerFormulaire();
     
     
            if(isset($_POST['enregistrer'])){
                    $utilisateur = new Intervenant();
     
     
     
                    $utilisateur->setIdIntervenant(IntervenantDAO::maxID()+1);
                    $utilisateur->setLogin($_POST['nomUtilisateur']);
                    $utilisateur->setMdp($_POST['mdp']);
                    $utilisateur->setPrenomIntervenant($_POST['prenom']);
                    $utilisateur->setNomIntervenant($_POST['nom']);
                    $utilisateur->setCodeStatut($_POST['codeS']);
     
     
                    IntervenantDAO::ajouterIntervenant($utilisateur);
            }
     
     
     
     
    require_once 'vue/vueInscription.php' ;
    Mon intervenantDAO (pas en entier, juste les fonctions auxquelles je fais appel) qui me permet d'avoir accès aux traitements relatifs à la BDD :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    public static function maxID()
        {
            $sql = "select MAX(idIntervenant) from intervenant";
            $req = dBConnex::getInstance()->prepare($sql);
            $req->execute();
            return $req->fetch();
        }
     
    public static function ajouterIntervenant(Intervenant $unIntervenant){
        	$sql = "insert into intervenant values (".$unIntervenant->getIdUtilisateur().",'".$unIntervenant->getCodeStatut()."','".$unIntervenant->getLogin()."','".$unIntervenant->getMdp()."','".$unIntervenant->getPrenomIntervenant()."','".$unIntervenant->getNomIntervenant()."')";
     
        	return DBConnex::getInstance()->exec($sql);
        }
    Et le fichier intervenant (DTO) :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    <?php
    class Intervenant {
        use Hydrate;
        private $idIntervenant;
        private $login;
        private $mdp;
        private $codeStatut;
        private $nomIntervenant;
        private $prenomIntervenant;
     
        public function __construct($unId = NULL, $unLogin = NULL, $unmdp = NULL, $unstatut = NULL, $nomIntervenant = null, $prenomIntervenant = null){
            $this->idIntervenant = $unId;
            $this->login = $unLogin;
            $this->codeStatut = $unstatut;
            $this->mdp = $unmdp;
            $this->nomIntervenant = $nomIntervenant;
            $this->prenomIntervenant = $prenomIntervenant;
        }
     
        public function getLogin()
        {
            return $this->login;
        }
     
        public function getMdp()
        {
            return $this->mdp;
        }
     
        public function getCodeStatut()
        {
            return $this->codeStatut;
        }
     
     
     
        public function setLogin($login)
        {
            $this->login = $login;
        }
     
        public function setMdp($mdp)
        {
            $this->mdp = $mdp;
        }
     
        public function setCodeStatut($codeStatut)
        {
            $this->codeStatut = $codeStatut;
        }
        public function getIdIntervenant()
        {
            return $this->idIntervenant;
        }
     
        public function setIdIntervenant($idIntervenant)
        {
            $this->idIntervenant = $idIntervenant;
        }
     
        public function getNomIntervenant()
        {
            return $this->nomIntervenant;
        }
     
        public function getPrenomIntervenant()
        {
            return $this->prenomIntervenant;
        }
     
        public function setNomIntervenant($nomIntervenant)
        {
            $this->nomIntervenant = $nomIntervenant;
        }
     
        public function setPrenomIntervenant($prenomIntervenant)
        {
            $this->prenomIntervenant = $prenomIntervenant;
        }
     
    }
    J'aurais donc besoin d'aide pour pouvoir comprendre mon erreur.

    De mon côté, j'ai essayé de récrire la requête avec des requêtes paramétrées (bindParam..) mais l'erreur persistait. Vu que l'erreur concerne seulement le type, je ne vois pas en quoi l'incrémentation de deux nombres causes un soucis.. Mais vu que la fonction maxID() -> retourne un tableau contenant un entier, ça pourrait être le problème de type.

    Merci !

  2. #2
    Expert confirmé
    Avatar de rawsrc
    Homme Profil pro
    Dev indep
    Inscrit en
    Mars 2004
    Messages
    6 142
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Dev indep

    Informations forums :
    Inscription : Mars 2004
    Messages : 6 142
    Billets dans le blog
    12
    Par défaut
    Salut,

    tu dois modifier la fonction maxId(),
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    public static function maxID()
    {
        $sql = 'SELECT MAX(idIntervenant) AS `maxId` FROM intervenant';
        $req = dBConnex::getInstance()->prepare($sql); // pas besoin de préparer, il n'y a aucune valeur à passer
        $req->execute();
        return (int)$req->fetchAll()[0]['maxId'];
    }

  3. #3
    Expert confirmé Avatar de Toufik83
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2012
    Messages
    2 518
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2012
    Messages : 2 518
    Par défaut
    Salut,

    fetchColumn est adaptée à ce genre de résultat, donc :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    public static function maxID()
        {
            $sql = "select MAX(idIntervenant) from intervenant";
            $req = dBConnex::getInstance()->prepare($sql);
            $req->execute();
            return $req->fetchColumn(); 
        }

  4. #4
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2017
    Messages
    95
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 25
    Localisation : France, Loiret (Centre)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2017
    Messages : 95
    Par défaut
    Merci beaucoup,

    J'ai pu résoudre mon problème grâce à votre aide. Une autre erreur persistait mais c'est une faute d'attention de ma part.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 6
    Dernier message: 15/05/2013, 13h06
  2. [PHP 5.2] Fatal error: Unsupported operand types
    Par ju0123456789 dans le forum Langage
    Réponses: 2
    Dernier message: 12/07/2010, 18h07
  3. Réponses: 2
    Dernier message: 25/03/2009, 21h40
  4. [MySQL] Fatal error: Unsupported operand types in..
    Par Sekigawa dans le forum PHP & Base de données
    Réponses: 2
    Dernier message: 20/03/2008, 10h58
  5. [PEAR][DB] Unsupported operand types in Renderer.php
    Par brissou dans le forum Bibliothèques et frameworks
    Réponses: 4
    Dernier message: 10/05/2007, 13h50

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo