Partage
  • Partager sur Facebook
  • Partager sur Twitter

formulaire inscription + php

Sujet résolu
    20 mai 2019 à 7:58:08

    Bonjour,

    j'ai un formulaire d'inscription sauf que je ne parviens pas a le faire fonctionner.

    j'ai vérifier plusieurs fois mais je ne parviens pas a corriger l'erreur

    voici mon code :

    <?php
    
        if (empty($_SESSION['Employe'])) {
    	    //NON Co
    
    	?>
    
        <div class= "row align-items-start">
            <div class="header-text hidden-xs">
                <div class="col-12 col-md-12 text-center unis_quest">
                    <h2 class="faire">
                        <span>
                            Que d&eacute;sirez vous faire ?
                        </span>
                    </h2>
                </div>
                <br>
                <div class="col-12 col-md-12 unis_bouton">
                    <div class="btn-group" role="group" aria-label="Basic example">
                        <a class="btn btn-connect" button type="button-middle" href="?page=connexion" title="Ouvrir la page">Se connecter</a>&nbsp;
                        <a class="btn btn-inscrit" button type="button-middle" href="?page=inscription" title="Ouvrir la page">S'inscrire</a>
                    </div>
                </div>
            </div>
        </div>
    
    
    	<?php
    
    }else {
    
    	echo '<pre>' . print_r( $_POST, true ) . '</pre>';
    	$_GET['action'] = 'connexion';
    	if ( ! empty( $_POST ) ) {
    		if ( ! isset(
    			$_POST['nom'],
    			$_POST['prenom'],
    			$_POST['adresse1'],
    			$_POST['adresse2'],
    			$_POST['codePostal'],
    			$_POST['ville'],
    			$_POST['telephone'],
    			$_POST['pays'],
    			$_POST['email'],
    			$_POST['handicap'],
    			$_POST['permis'],
    			$_POST['vehicule']
    
    
    		) ) {
    			echo "il manque une ou plusieurs donnees";
    		} else {
    //remonté dans l'index
    // 		require_once '../../include/autoload.php';
    			try {
    				$managerVolontaire = new ManagerVolontaire();
    				$managerVolontaire->add( $_POST );
    //devenu inutile => a supprimer
    //require_once( 'accueil.tpl' );
    //redirection vers la connexion
    				$_GET['action'] = 'accueil';
    			} catch ( LengthException $lengthException ) {
    //cas longueur == 0
    				echo $lengthException->GetMessage();
    			} catch ( Exception $exception ) {
    //aute cas (mais pour nous invalide)
    				echo $exception->GetMessage();
    			}
    
    		}
    	}
    	?>
    
    
        <div class="row align-items-start">
    
            <div class="col-12 col-md-8 unis_volontaire">
                <section class="page-section">
                    <form action="?page=volontaire" method="post">
                        <div class="form-group">
                            <label for="nom"> Nom : </label><input type="text" class="form-control" aria-describedby="nom"
                                                                   id="nom" name="nom">
                        </div>
                        <span id="nom_manquant">
                        </span>
    
                        <div class="form-group">
                            <label for="prenom"> Prenom : </label><input type="text" class="form-control"
                                                                         aria-describedby="Prenom" id="prenom"
                                                                         name="prenom">
                        </div>
                        <span id="prenom_manquant">
                        </span>
    
                        <div class="form-group">
                            <label for="adresse"> Adresse : </label><input type="text" class="form-control"
                                                                           aria-describedby="Adresse" id="adresse1"
                                                                           name="adresse1">
                        </div>
                        <span id="Adresse_manquant">
                        </span>
    
                        <div class="form-group">
                            <label for="adresse"> Adresse : </label><input type="text" class="form-control"
                                                                           aria-describedby="Adresse" id="adresse2"
                                                                           name="adresse2">
                        </div>
    
                        <div class="form-group">
                            <label for="codePostal"> Code Postal : </label><input type="text" class="form-control"
                                                                                  aria-describedby="codePostal"
                                                                                  id="codePostal" name="codePostal">
                        </div>
                        <span id="code_manquant">
                        </span>
    
                        <div class="form-group">
                            <label for="ville"> Ville : </label><input type="text" class="form-control"
                                                                       aria-describedby="ville" id="ville" name="ville">
                        </div>
                        <span id="ville_manquant">
                        </span>
    
                        <div class="form-group">
                            <label for="pays"> Pays : </label><input type="text" class="form-control"
                                                                     aria-describedby="Pays" id="pays" name="pays">
                        </div>
                        <span id="Pays_manquant">
                        </span>
    
                        <div class="form-group">
                            <label for="email"> e-mail : </label><input type="email" class="form-control"
                                                                        aria-describedby="email" id="email" name="email">
                        </div>
                        <span id="email_manquant">
                        </span>
    
                        <div class="form-group">
                            <label for="telephone"> telephone : </label><input type="tel" class="form-control"
                                                                               aria-describedby="telephone" id="telephone"
                                                                               name="telephone"
                                                                               pattern="^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,5})|(\(?\d{2,6}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$">
                        </div>
                        <span id="telephone_manquant">
                        </span>
    
                        <div class="form-group">
                            <label for="handicape"> handicape ( si oui : rqth ou autre) : </label>
                            <input type="radio" name="handicap" value="oui">oui &nbsp;
                            <input type="radio" name="handicap" value="non">non
                            <label for="quelhandicap"> Lequel?</label>
                            <input type="text" class="form-control" aria-describedby="handicape" id="quelhandicap" name="typeHandicap">
                        </div>
    
    
                        <div class="form-group">
                            <label for="permis"> permis : </label><input type="text" class="form-control"
                                                                         aria-describedby="permis" id="permis"
                                                                         name="permis">
                        </div>
    
                        <div class="form-group">
                            <label for="vehicule"> véhicule : </label><input type="text" class="form-control"
                                                                             aria-describedby="vehicule" id="vehicule"
                                                                             name="vehicule">
                        </div>
    
                        <p>
                            <input type="submit" id="button" class="btn-inscrit" value="Inscription">
                        </p>
                    </form>
                </section>
    
                <p class="volontaire">Vous désirez consulter la liste des volontaire ? Rendez vous sur cette <a
                            href="?page=liste_volontaire" name="page">
                        page.
                </p>
    
            </div>
        </div>
    
    	<?php
    }
    <?php
    /**
     * Created by PhpStorm.
     * User: Adeline
     * Date: 30/01/2019
     * Time: 19:29
     */
    
    class Personne {
    
    	protected $id;
    	protected $nom;
    	protected $prenom;
    	protected $adresse1;
    	protected $adresse2;
    	protected $codePostal;
    	protected $email;
    	protected $ville;
    	protected $telephone;
    	protected $pays;
    	protected $handicap;
    	protected $permis;
    	protected $vehicule;
    
    	public function __construct( array $data =[] ) {
    	    if (!empty($data)) {
    	        $this->hydrate($data);
    	    } else {
    	        throw new Exception("Aucune donnees");
    	    }
    	}
    
    	public function getId() {
    		return $this->id;
    	}
    
    
    	public function getNom() {
    		return $this->nom;
    	}
    
    	/**
    	 * @return mixed
    	 */
    	public function getPrenom() {
    		return $this->prenom;
    	}
    
    	/**
    	 * @return mixed
    	 */
    	public function getAdresse1() {
    		return $this->adresse1;
    	}
    
    	/**
    	 * @return mixed
    	 */
    	public function getAdresse2() {
    		return $this->adresse2;
    	}
    
    	/**
    	 * @return mixed
    	 */
    	public function getCodePostal() {
    		return $this->codePostal;
    	}
    
    	/**
    	 * @return mixed
    	 */
    	public function getVille() {
    		return $this->ville;
    	}
    
    	/**
    	 * @return mixed
    	 */
    	public function getPays() {
    		return $this->pays;
    	}
    
    	/**
    	 * @return mixed
    	 */
    	public function gethandicap() {
    		return $this->handicap;
    	}
    
    	/**
    	 * @return mixed
    	 */
    	public function getEmail() {
    		return $this->email;
    	}
    
    	/**
    	 * @return mixed
    	 */
    	public function getTelephone() {
    		return $this->telephone;
    	}
    
    	/**
    	 * @return mixed
    	 */
    	public function getPermis() {
    		return $this->permis;
    	}
    
    	/**
    	 * @return mixed
    	 */
    	public function getVehicule() {
    		return $this->vehicule;
    	}
    
    	/**
    	 * @param mixed $id_personne
    	 */
    	public function setId( $id ){
    		echo '<br>[debug]Dans "'.__FUNCTION__.'" [/debug]';
    		$id = (int) $id;
    		if ($id > 0)
    		{
    			$this->id = $id;
    		}
    	}
    
    
    	public function setNom( $nom ) {
    		if (strlen(trim($nom)) > 0)
    			//strlen = Calcule la taille d'une cha�ne
    			// trim = Supprime les espaces (ou d'autres caract�res) en d�but et fin de cha�ne
    		{
    			if (strpos($nom,"#") !== false)
    				// strpos = Cherche la position de la premi�re occurrence dans une cha�ne
    			{
    				throw new Exception("Le nom ne peut pas avoir de caracteres speciaux");
    			}
    			if (preg_match("/[0-9]/", "$nom"))
    				// preg_match = sert ici pour les cfiffres
    			{
    				throw new Exception("Le nom ne peut pas avoir de chiffre");
    			}
    			else
    			{
    				//echo "la cha�ne $nom est correcte";
    				$this->nom = $nom;
    			}
    		}
    	}
    
    
    	public function setPrenom( $prenom ) {
    		if (strlen(trim($prenom)) > 0)
    		{
    			if (strpos($prenom,"#") !== false)
    			{
    				throw new Exception("Le prenom ne peut pas avoir de caracteres speciaux");
    			}
    
    			if (preg_match("/[0-9]/", "$prenom"))
    			{
    				throw new Exception("Le prenom ne peut pas avoir de chiffre");
    			}
    
    			else
    			{
    				//echo "la cha�ne $prenom est correcte";
    				$this->prenom = $prenom;
    			}
    		}
    	}
    
    	/**
    	 * @param mixed $adresse1
    	 */
    	public function setAdresse1( $adresse1 ) {
    		if (strlen(trim($adresse1)) > 0)
    		{
    			$this->adresse1 = $adresse1;
    		}else{
    			echo "l'adresse est obligatoire";
    		}
    	}
    
    	/**
    	 * @param mixed $adresse2
    	 */
    	public function setAdresse2( $adresse2 ) {
    		if (strlen(trim($adresse2)) > 0)
    		{
    			$this->adresse2 = $adresse2;
    		}
    	}//pas de else
    
    	/**
    	 * @param mixed $codePostal
    	 */
    	public function setCodePostal( $codePostal ) {
    		if (preg_match('/[0-9]{5}/',$codePostal))
    		{
    			$this->codePostal = $codePostal;
    		} else {
    			echo "<br/>Aucun r&eacute;sultat n'a &eacute;t&eacute; trouv&eacute;.";
    		}
    	}
    
    	public function setVille( $ville ) {
    		if (strlen(trim($ville)) > 0)
    		{
    			$this->ville = $ville;
    
    			if (preg_match("/[0-9]/", "$ville"))
    			{
    				throw new Exception("La ville ne peut pas avoir de chiffre");
    			}
    
    		}else{
    			echo "la ville est obligatoire";
    		}
    	}
    
    	/**
    	 * @param mixed $pays
    	 */
    	public function setPays( $pays ) {
    		if (strlen(trim($pays)) > 0)
    		{
    			$this->pays = $pays;
    
    			if (preg_match("/[0-9]/", "$pays"))
    			{
    				throw new Exception("La ville ne peut pas avoir de chiffre");
    			}
    
    		}else{
    			echo "le pays est obligatoire";
    		}
    	}
    
    	/**
    	 * @param mixed $email
    	 */
    	public function setEmail( $email ) {
    		//1) si la chaine n'est pas vide
    		if (strlen(trim($email)) == 0) {
    			//erreur
    			throw new LengthException("Le mail est vide",100); //code 100 == mail vide
    		} else {
    			//pas d'erreur on continue
    // 			if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
    // 				//mail valid�
    				$this->email = $email;
    // 			} else {
    // 				//erreur � g�rer
    // 				throw new Exception("Le mail est invalide",101); //code 101 == mail invalide
    // 			}
    		}
    	}
    
    	/**
    	 * @param mixed $telephone
    	 */
    	public function setTelephone( $telephone ) {
    		$this->telephone = $telephone;
    	}
    
    	/**
    	 * @param mixed $handicap
    	 */
    	public function setHandicap( $handicap ) {
    		$this->handicap = $handicap;
    	}
    
    	/**
    	 * @param mixed $permis
    	 */
    	public function setPermis( $permis ) {
    		$this->permis = $permis;
    	}
    
    	/**
    	 * @param mixed $vehicule
    	 */
    	public function setVehicule( $vehicule ) {
    		$this->vehicule = $vehicule;
    	}
    	
    	
    	protected function hydrate($array){
    	    echo '<br>[debug]Dans "'.__FUNCTION__.'" [/debug]';
    	    foreach ($array as $key => $value) {
    	        $methodName = 'set'.ucfirst($key);
    	        if(method_exists($this, $methodName)){
    	            $this->$methodName($value);
    	        }
    	    }
    	}
    
    }
    <?php
    /**
     * Created by PhpStorm.
     * User: Adeline
     * Date: 11/11/2018
     * Time: 17:54
     */
    
    class Volontaire extends Personne {
    
    	protected $id;
    	protected $pre_inscrit;
    
    	public function __construct( array $array =[] )
    	{
    		$this->hydrate($array);
    	}
    
    
    	public function getId() {
    		return $this->id;
    	}
    	
    	
    	/**
    	 * @return mixed
    	 */
    	public function getPre_inscrit()
    	{
    	    return $this->pre_inscrit;
    	}
    	
    	/**
    	 * @param mixed $pre_inscrit
    	 */
    	public function setPre_inscrit($pre_inscrit)
    	{
    	    $this->pre_inscrit = $pre_inscrit;
    	}
    
    	public function setId( $id ){
    		echo '<br>[debug]Dans "'.__FUNCTION__.'" [/debug]';
    		$id = (int) $id;
    		if ($id > 0)
    		{
    			$this->id = $id;
    		} else {
    		    throw new Exception("Un identifiant est un entier");
    		}
    	}
    
    	protected function hydrate($array){
    		echo '<br>[debug]Dans "'.__FUNCTION__.'" [/debug]';
    		foreach ($array as $key => $value) {
    			$methodName = 'set'.ucfirst($key);
    			if(method_exists($this, $methodName)){
    				$this->$methodName($value);
    			}
    		}
    	}
    
    }
    <?php
    /**
     * Created by PhpStorm.
     * User: Adeline
     * Date: 11/11/2018
     * Time: 17:56
     */
    
    class ManagerVolontaire extends Manager {
        
        public function __construct($mode='prod'){
            parent::__construct($mode);
        }
    
    
    
    
    	public function read($id){
    		echo '<br>[debug]Dans "'.__FUNCTION__.'" [/debug]';
    		$req = $this->db->prepare('SELECT * FROM volontaire WHERE $id=:$id');
    		$req->bindValue('$id', $id, PDO::PARAM_INT);
    		$req->execute();
    		$array = $req->fetch();
    		$volontaire = new volontaire($array);
    
    		return $volontaire;
    	}
    
    	public function add( $data ) {
    		echo '<br>[debug]Dans "'.__FUNCTION__.'" [/debug]';
    		//bloc try/catch pour gérer les exceptions
    		//provenant de Client
    		try {
    			$volontaire = new volontaire($data);
    		} catch (LengthException $lengthException) {
    			//cas longueur == 0
    			throw new Exception($lengthException->GetMessage(),$lengthException->GetCode());
    		} catch (Exception $exception) {
    			//autre cas (mais pour nous invalide)
    			throw new Exception($exception->GetMessage(),$exception->GetCode());
    		}
    		$req = $this->db->prepare('INSERT INTO volontaire (pre_inscrit,nom,prenom,adresse1,adresse2,codePostal,ville,pays,email,telephone,handicap,permis,vehicule) VALUES(:pre_inscrit,:nom,:prenom,:adresse1,:adresse2,:codePostal,:ville,:pays,:email,:telephone,:handicap,:permis,:vehicule)');
    		$req->bindValue('pre_inscrit', $volontaire->getPre_inscrit(), PDO::PARAM_STR);
    		$req->bindValue('nom', $volontaire->getNom(), PDO::PARAM_STR);
    		$req->bindValue('prenom', $volontaire->getPrenom(), PDO::PARAM_STR);
    		$req->bindValue('adresse1', $volontaire->getAdresse1(), PDO::PARAM_STR);
    		$req->bindValue('adresse2', $volontaire->getAdresse2(), PDO::PARAM_STR);
    		$req->bindValue('codePostal', $volontaire->getCodePostal(), PDO::PARAM_STR);
    		$req->bindValue('ville', $volontaire->getVille(), PDO::PARAM_STR);
    		$req->bindValue('pays', $volontaire->getPays(), PDO::PARAM_STR);
    		$req->bindValue('email', $volontaire->getEmail(), PDO::PARAM_STR);
    		$req->bindValue('telephone', $volontaire->getTelephone(), PDO::PARAM_STR);
    		$req->bindValue('handicap', ((is_null($volontaire->getHandicap())) ? ' ' : $volontaire->getHandicap()), PDO::PARAM_STR);
    		$req->bindValue('permis', $volontaire->getPermis(), PDO::PARAM_STR);
    		$req->bindValue('vehicule', $volontaire->getVehicule(), PDO::PARAM_STR);
    		$req->execute();
    		$id = $this->db->lastInsertId();
    		$volontaire->setId( $id );
    	}
    
    	public function getAllVolontaire() {
    		$stm = "SELECT * FROM volontaire";
    		//Ceci:
    //         $stmt = $this->connexion->query($req);
    //         return $stmt;
    		//resum� par cela
    		return $this->db->query( $stm );
    	}
    
    	public function getVolontaire( $id ) {
    		$stm = "SELECT * FROM volontaire WHERE id=:id";
    		//preparation == protection des donn?es ? venir
    		$stmt = $this->db->prepare( $stm );
    		//liaison des marqueur :toto aux donnees
    		$stmt->bindValue( 'id', $id, PDO::PARAM_INT );
    		//execution de la requete sur le serveur SQL
    		$stmt->execute();
    
    		return $stmt;
    	}
    
    	public function update( $data ) {
    		echo '<pre>' . print_r( $data, true ) . '</pre>';
    
    		echo '<br>[debug]SESSION';
    		echo '<pre>' . print_r( $data, true ) . '</pre>';
    
    		$req = $this->db->prepare('UPDATE volontaire SET nom=:nom,prenom=:prenom,adresse1=:adresse1,adresse2=:adresse2,codePostal=:codePostal,ville=:ville,pays=:pays,email=:email, telephone=:telephone, handicap=:handicap, permis=:permis, vehicule=:vehicule,pre_inscrit=:pre_inscrit WHERE id = :id');
    		$req->bindValue( 'id', $data->getId(), PDO::PARAM_INT );
    		$req->bindValue('nom', $data->getNom(), PDO::PARAM_STR);
    		$req->bindValue('prenom', $data->getPrenom(), PDO::PARAM_STR);
    		$req->bindValue('adresse1', $data->getAdresse1(), PDO::PARAM_STR);
    		$req->bindValue('adresse2', $data->getAdresse2(), PDO::PARAM_STR);
    		$req->bindValue('codePostal', $data->getCodePostal(), PDO::PARAM_STR);
    		$req->bindValue('ville', $data->getVille(), PDO::PARAM_STR);
    		$req->bindValue('pays', $data->getPays(), PDO::PARAM_STR);
    		$req->bindValue('email', $data->getEmail(), PDO::PARAM_STR);
    		$req->bindValue('telephone', $data->getTelephone(), PDO::PARAM_STR);
    		$req->bindValue('handicap', $data->getHandicap(), PDO::PARAM_STR);
    		$req->bindValue('permis', $data->getPermis(), PDO::PARAM_STR);
    		$req->bindValue('vehicule', $data->getVehicule(), PDO::PARAM_STR);
    		$req->bindValue('pre_inscrit', $data->getPre_inscrit(), PDO::PARAM_STR);
    		if (! $req->execute()) {
    			echo "<br>[debug] Erreur";
    		}
    	}
    
        public function getListe() {
            echo '<br>[debug]Dans "'.__FUNCTION__.'" [/debug]';
            $req = $this->db->query('SELECT * FROM volontaire'); // 1 � N lignes
            
            //init tableau des volontaires
            $aVolontaires = array();
            
            //Parcours des N lignes trouv�es dans la table Volontaire
            while ($dataVolontaire = $req->fetch()) {
                //on stocke un volontaire par case du tableau
                $aVolontaires[] = new Volontaire($dataVolontaire);
            }
            
            //on retourne le tableau        
            return $aVolontaires;
        }
    
    	public function delete( $id ) {
    		// =>voir  getLivre(id) pour modele
    		$req  = "DELETE FROM volontaire WHERE id=:id";
    		$stmt = $this->db->prepare( $req );
    		$stmt->execute();
    		if ( $stmt->rowCount() == 1 ) {
    			echo '[debug]OK 1 ligne inseree';
    		} else {
    			echo 'Erreur insertion donnees';
    		}
    
    	}
    
    
    }
    -- phpMyAdmin SQL Dump
    -- version 4.8.0.1
    -- https://www.phpmyadmin.net/
    --
    -- Hôte : 127.0.0.1:3306
    -- Généré le :  Dim 19 mai 2019 à 19:35
    -- Version du serveur :  5.7.21
    -- Version de PHP :  7.2.4
    
    SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
    SET AUTOCOMMIT = 0;
    START TRANSACTION;
    SET time_zone = "+00:00";
    
    
    /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
    /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
    /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
    /*!40101 SET NAMES utf8mb4 */;
    
    --
    -- Base de données :  `uniscite`
    --
    
    -- --------------------------------------------------------
    
    --
    -- Structure de la table `assurance`
    --
    
    DROP TABLE IF EXISTS `assurance`;
    CREATE TABLE IF NOT EXISTS `assurance` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `nom` varchar(50) NOT NULL,
      `codePostal` varchar(5) NOT NULL,
      `email` varchar(500) NOT NULL,
      `ville` varchar(500) NOT NULL,
      `telephone` varchar(500) NOT NULL,
      `pays` varchar(500) NOT NULL,
      `numAssurer` varchar(50) NOT NULL,
      `adresse1` varchar(500) NOT NULL,
      `adresse2` varchar(500) NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    
    -- --------------------------------------------------------
    
    --
    -- Structure de la table `assurance_habitation`
    --
    
    DROP TABLE IF EXISTS `assurance_habitation`;
    CREATE TABLE IF NOT EXISTS `assurance_habitation` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `assurance` int(11) DEFAULT '3',
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    
    -- --------------------------------------------------------
    
    --
    -- Structure de la table `assurance_vehicule`
    --
    
    DROP TABLE IF EXISTS `assurance_vehicule`;
    CREATE TABLE IF NOT EXISTS `assurance_vehicule` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `assurance` int(11) DEFAULT '1',
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    
    -- --------------------------------------------------------
    
    --
    -- Structure de la table `assurance_vie`
    --
    
    DROP TABLE IF EXISTS `assurance_vie`;
    CREATE TABLE IF NOT EXISTS `assurance_vie` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `assurance` int(11) DEFAULT '2',
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    
    -- --------------------------------------------------------
    
    --
    -- Structure de la table `assure`
    --
    
    DROP TABLE IF EXISTS `assure`;
    CREATE TABLE IF NOT EXISTS `assure` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `assurance` int(11) DEFAULT '0',
      `employe` int(11) DEFAULT '0',
      `volontaire` int(11) DEFAULT '0',
      PRIMARY KEY (`id`),
      KEY `assurance` (`assurance`),
      KEY `employe` (`employe`),
      KEY `volontaire` (`volontaire`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    
    -- --------------------------------------------------------
    
    --
    -- Structure de la table `employe`
    --
    
    DROP TABLE IF EXISTS `employe`;
    CREATE TABLE IF NOT EXISTS `employe` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `password` varchar(500) NOT NULL,
      `nom` varchar(100) NOT NULL,
      `prenom` varchar(100) NOT NULL,
      `adresse1` varchar(500) NOT NULL,
      `adresse2` varchar(500) NOT NULL,
      `codePostal` varchar(5) NOT NULL,
      `email` varchar(500) NOT NULL,
      `ville` varchar(500) NOT NULL,
      `telephone` varchar(15) NOT NULL,
      `pays` varchar(15) NOT NULL,
      `handicap` varchar(150) NOT NULL,
      `permis` varchar(150) NOT NULL,
      `vehicule` varchar(3) NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
    
    --
    -- Déchargement des données de la table `employe`
    --
    
    INSERT INTO `employe` (`id`, `password`, `nom`, `prenom`, `adresse1`, `adresse2`, `codePostal`, `email`, `ville`, `telephone`, `pays`, `handicap`, `permis`, `vehicule`) VALUES
    (1, '$2y$10$6juUOz1aLq6RyUyoXoROB.R13LjARAMQdbZwGDWVrpYr.cb4xt1eG', 'ddd', 'dffds', '4 tuope', 'rme', '65402', 'toto@gmail.com', 'pau', '0875652135', 'gre', 'oui', 'b', 'rte');
    
    -- --------------------------------------------------------
    
    --
    -- Structure de la table `possede`
    --
    
    DROP TABLE IF EXISTS `possede`;
    CREATE TABLE IF NOT EXISTS `possede` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `vehicule` int(11) DEFAULT '0',
      `employe` int(11) DEFAULT '0',
      `volontaire` int(11) DEFAULT '0',
      PRIMARY KEY (`id`),
      KEY `employe` (`employe`),
      KEY `volontaire` (`volontaire`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    
    -- --------------------------------------------------------
    
    --
    -- Structure de la table `reunion`
    --
    
    DROP TABLE IF EXISTS `reunion`;
    CREATE TABLE IF NOT EXISTS `reunion` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `date` datetime NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    
    -- --------------------------------------------------------
    
    --
    -- Structure de la table `reunion_employe`
    --
    
    DROP TABLE IF EXISTS `reunion_employe`;
    CREATE TABLE IF NOT EXISTS `reunion_employe` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `reunion` int(11) DEFAULT '0',
      `employe` int(11) DEFAULT '0',
      `volontaire` int(11) DEFAULT '0',
      PRIMARY KEY (`id`),
      KEY `reunion` (`reunion`),
      KEY `employe` (`employe`),
      KEY `volontaire` (`volontaire`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    
    -- --------------------------------------------------------
    
    --
    -- Structure de la table `vehicule`
    --
    
    DROP TABLE IF EXISTS `vehicule`;
    CREATE TABLE IF NOT EXISTS `vehicule` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `nom` varchar(500) NOT NULL,
      `type_vehicule` varchar(500) NOT NULL,
      `immatriculation` varchar(500) NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
    
    --
    -- Déchargement des données de la table `vehicule`
    --
    
    INSERT INTO `vehicule` (`id`, `nom`, `type_vehicule`, `immatriculation`) VALUES
    (1, 'kjh', 'pou', '2162');
    
    -- --------------------------------------------------------
    
    --
    -- Structure de la table `volontaire`
    --
    
    DROP TABLE IF EXISTS `volontaire`;
    CREATE TABLE IF NOT EXISTS `volontaire` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `pre_inscrit` varchar(50) DEFAULT '1',
      `nom` varchar(100) NOT NULL,
      `prenom` varchar(100) NOT NULL,
      `adresse1` varchar(500) NOT NULL,
      `adresse2` varchar(500) NOT NULL,
      `codePostal` varchar(5) NOT NULL,
      `email` varchar(500) NOT NULL,
      `ville` varchar(500) NOT NULL,
      `telephone` varchar(15) NOT NULL,
      `pays` varchar(15) NOT NULL,
      `handicap` varchar(150) NOT NULL,
      `permis` varchar(150) NOT NULL,
      `vehicule` varchar(3) NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    
    --
    -- Contraintes pour les tables déchargées
    --
    
    --
    -- Contraintes pour la table `assure`
    --
    ALTER TABLE `assure`
      ADD CONSTRAINT `assure_ibfk_1` FOREIGN KEY (`assurance`) REFERENCES `assurance` (`id`),
      ADD CONSTRAINT `assure_ibfk_2` FOREIGN KEY (`employe`) REFERENCES `employe` (`id`),
      ADD CONSTRAINT `assure_ibfk_3` FOREIGN KEY (`volontaire`) REFERENCES `volontaire` (`id`);
    
    --
    -- Contraintes pour la table `possede`
    --
    ALTER TABLE `possede`
      ADD CONSTRAINT `possede_ibfk_1` FOREIGN KEY (`employe`) REFERENCES `employe` (`id`),
      ADD CONSTRAINT `possede_ibfk_2` FOREIGN KEY (`volontaire`) REFERENCES `volontaire` (`id`);
    
    --
    -- Contraintes pour la table `reunion_employe`
    --
    ALTER TABLE `reunion_employe`
      ADD CONSTRAINT `reunion_employe_ibfk_1` FOREIGN KEY (`reunion`) REFERENCES `reunion` (`id`),
      ADD CONSTRAINT `reunion_employe_ibfk_2` FOREIGN KEY (`employe`) REFERENCES `employe` (`id`),
      ADD CONSTRAINT `reunion_employe_ibfk_3` FOREIGN KEY (`volontaire`) REFERENCES `volontaire` (`id`);
    COMMIT;
    
    /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
    /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
    /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
    
    Array
    (
        [nom] => groupama
        [prenom] => dffds
        [adresse1] => 4 tuope
        [adresse2] => rme
        [codePostal] => 65402
        [ville] => pau
        [pays] => gre
        [email] => test@test.test
        [telephone] => 0875652135
        [handicap] => oui
        [typeHandicap] => gre
        [permis] => b
        [vehicule] => rte
    )
    


    [debug]Dans "add" [/debug]
    [debug]Dans "hydrate" [/debug]

    ( ! ) Fatal error: Uncaught Error: Call to a member function prepare() on null in C:\wamp\www\uniscite\code\php\class\ManagerVolontaire.class.php on line 42
    ( ! ) Error: Call to a member function prepare() on null in C:\wamp\www\uniscite\code\php\class\ManagerVolontaire.class.php on line 42
    Call Stack
    #TimeMemoryFunctionLocation
    1 0.0008 392376 {main}( ) ...\index.php:0
    2 0.0071 414264 include_once( 'C:\wamp\www\uniscite\code\templates\volontaire.php' ) ...\index.php:128
    3 0.0086 416000 ManagerVolontaire->add( ) ...\volontaire.php:57

    merci pour votre aide

    • Partager sur Facebook
    • Partager sur Twitter

    Merci à tous. Vous pouvez me retrouver ici :

    🌐 Visitez mon profil sur Comeup

    🚀 Découvrez BeFreelancr

    📱 Retrouvez-moi sur LinkedIn

      20 mai 2019 à 9:00:04

      Bonjour,

      L'erreur t'indique que ta connexion à la bdd n'est pas faite (tu fais un prepare sur quelque chose qui est NULL).

      Tu pourras également te pencher sur ceci :

          public function read($id){
              echo '<br>[debug]Dans "'.__FUNCTION__.'" [/debug]';
              $req = $this->db->prepare('SELECT * FROM volontaire WHERE $id=:$id');
              $req->bindValue('$id', $id, PDO::PARAM_INT);
              $req->execute();
              $array = $req->fetch();
              $volontaire = new volontaire($array);
       
              return $volontaire;
          }



      • Partager sur Facebook
      • Partager sur Twitter
        20 mai 2019 à 11:05:47

        Salut,

        Je ne comprends pas comment tu fais pour louper la connexion à chaque fois sachant qu'elle es tinitialisé dans l'index.

        Comment tu appelles tes page ?

        Et rapido:

        SELECT * FROM volontaire WHERE $id=:$id

        devient

        SELECT * FROM volontaire WHERE id=:id




        • Partager sur Facebook
        • Partager sur Twitter

        formulaire inscription + php

        × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
        × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
        • Editeur
        • Markdown