Ajouter une photo sur le profil utilisateur [Résolu]

Signaler
-
 Janyduchemin -
Bonjour,
J'essaye en vain d'ajouter un code sur le profil utilisateur afin de permettre à ce dernier d'ajouter sa photo mais je reçois ces erreurs.

Notice: Undefined variable: photo in C:\wamp\www\ndameyong\Classes\Db.php on line 56

Warning: PDOStatement::execute() expects at most 1 parameter, 2 given in C:\wamp\www\ndameyong\Classes\Db.php on line 56

j'ai de besoin de votre aide pour remédier à ce problème...Merci d'avance je vous laisse les différents codes

1) profil.php

<?php require 'includes/includes.php';
if(!Auth::islog($DB)){
    header('location:index.php');
    exit(); 
    }
 
$user = $_SESSION['user'];
if(!empty($_POST)){
    $validate = true;
 
    // valider l'email
    if(empty($_POST['email'])){
        $validate = false;
        $erreur_email = 'Le champ email est requis !';
      }else
          if(!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)){
            $validate = false;
                $erreur_email = "Veuillez entrer une adresse email valide.";
          }
          // VÉRIFIER LE PASSWORD
    if(empty($_POST['password'])){
      $password = $_SESSION['user']['password'];
    }elseif(empty($_POST['confirm_password'])){
        $erreur_password = "Confirmer votre mot de passe";
        $validate =false;
      }elseif ($_POST['confirm_password'] != $_POST['password']){
        $erreur_password = "Le mot de passe et le mot de passe confirmation sont différents.";
        $validate =false;
      }else{
        $password = User::hashPassword($_POST['password']);
      }
 
      if(!empty($_FILES['photo']['name']))
    {
      $photo = $_FILES['photo'];
 
      $filePath = 'photos/'.$user->id;
      $thumbPath = $filePath.'/thumbnail';
 
 
      @mkdir($filePath, 0777, true);
 
      @mkdir($filePath.'/thumbnail', 0777, true);
 
      $allowedExt = ['jpeg', 'jpg', 'png'];
 
      $ext = strtolower(pathinfo($photo['name'], PATHINFO_EXTENSION));
 
      if(!in_array($ext, $allowedExt)){
        array_push($errors, 'Le fichier n\'est pas autorisé.');
      }
      else{
        $infos = getimagesize($photo['tmp_name']);
 
        $width = $infos[0];
 
        $height = $infos[1];
 
        if($width < 200 || $height < 200){
          array_push($errors, 'L\'image doit faire au moins 200px de large et 200px de hauteur.');
        }
        else{
          $filename = uniqid($user->id, true).'.'.$ext;
          move_uploaded_file($photo['tmp_name'], $filePath.'/'.$filename);
        }
      }
    }
 
    if($validate){
       $data = array(
            'id'=>$_SESSION['user']['id'],
            'nom_prenom' =>$_POST['nom_prenom'],
            'ville'   =>$_POST['ville'],
            'email'   =>$_POST['email'],  
            'password'=>$password
            );
        
        $rep = $DB->insert('UPDATE users SET nom_prenom=:nom_prenom,ville=:ville,photo=:photo,email=:email,password=:password WHERE id=:id',$data);
 
        if(!empty($oldFilePath) && !empty($filename)){
        @unlink($oldFilePath);
        @unlink($oldThumbFilePath);
       }
 
        if($rep){
            $_SESSION['message'] = "Votre profil a été mis à jour avec succès .";
            $_SESSION['user'] = array_merge($_SESSION['user'],$data);
            header('location:profil.php');
            exit();
        }else{
            $_SESSION['erreur'] = "Un problème est survenu lors de la sauvegarde !.";
        }
    }else{
        $_SESSION['erreur'] = "Veuillez corriger les érreurs indiquées ci dessous .";
    }
     
}
 
$orders  = $DB->query("SELECT * from orders WHERE user_id=:id",array('id'=>$_SESSION['user']['id']));
?>
 
<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Votre Espace Profil || Ndameyong - L'Ecole des Langues Camerounaises</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <!-- animate css-->
    <link rel="stylesheet" href="fonts/material-icon/css/material-design-iconic-font.min.css">
 
    <!-- Main css -->
    <link rel="stylesheet" href="css/profil.css">
    <link rel="stylesheet" href="css/admin_style.css">
    <link rel="stylesheet" href="css/admin_style2.css">
    <link rel="stylesheet" href="css/admin_main.css">
     
    <link rel="icon" type="image/png" sizes="16x16" href="favicon/favicon-16x16.png">
</head>
 
<body>
    <section class="wel-t-band">
        <div id="top-header">
               
         
              <ul class="header-links pull-left">
                  <li><a href="index.php"><i class="fa fa-heart"></i> Acceuil Ndameyong</a></li>
                  <li><a href="presentation.php"><i class="fa fa-heart"></i> Présentation du site</a></li>
                  <li><a href="http:/ndameyong/nkili/index.php"><i class="fa fa-heart"></i> La Boutique</a></li>              
              </ul>
               <ul class="header-links pull-right">
                  <?php if (isset($_SESSION['user'])): ?>
                  <?php if (Auth::isadmin($DB)): ?>
                  <li><a href="admin/">Administration</a></li>
                  <?php endif ?>
                  <li><a href="login.php?logout">Déconnexion</a></li>
                  <?php else: ?>
                  <li>|| <a href="signup.php">Nouveau membre</a> ||</li>
                  <li>|| <a href="login.php">Connexion</a> ||
                  </li>
                  <li>|| <a href="recuperation.php">Mot de passe oublié</a> ||
                  </li>
                   
                  <?php endif?>
              </ul>
               
        </div>
    </section>
 
 
<!-- Message dans la session -->
  <?php if (isset($_SESSION['message'])): ?>
    <div class="message"> <?php echo $_SESSION['message']; ?></div>
    <?php unset( $_SESSION['message']); ?>
  <?php endif ?>
   <?php if (isset($_SESSION['erreur'])): ?>
    <div class="errorMessage"> <?php echo $_SESSION['erreur']; ?></div>
    <?php unset( $_SESSION['erreur']); ?>
  <?php endif ?>
 
 
 
    <div class="main">
        <div class="container" style="margin-top:-160px">
            <h2>Modifier vos informations ici</h2>
 
 <?php include('messages.php');?>
 
            <form action ="profil.php" method="POST" id="signup-form" class="signup-form" enctype="multipart/form-data">
                <h3>
                    Votre Identité
                </h3>
 
                 <fieldset>
                    <div class="form-row">
                        <div class="form-file">
                            <input type="file" class="inputfile" name="your_picture" id="your_picture"  onchange="readURL(this);" data-multiple-caption="{count} files selected" multiple />
                            <label for="your_picture">
                                <figure>
                                    <img src="images/your-picture.png" alt="" class="your_picture_image">
                                </figure>
                                <span class="file-button">Ajoutez une photo <br/ >(format jpeg, jpg ou png d'au moins 200x200px)</span> <br/ >
                                <button type="submit" class="btn btn-primary">Envoyer</button>
                            </label>
                        </div>
 
                        <div class="form-group-flex">
                             <div class="form-group">
                                <input type="text" name="nom_prenom" value="<?php echo isset($_POST['nom_prenom'])?$_POST['nom_prenom']:$_SESSION['user']['nom_prenom']; ?>" placeholder="Nom_Prenom" />
                            </div>
                                <?php if (!empty($erreur_nom_prenom)): ?>
                                    <div class="error"><?php echo $erreur_nom_prenom; ?></div>
                                <?php endif ?>
                        </div>
                    </div>
                </fieldset>
                <h3>
                    Votre Mot de Passe
                </h3>
                <fieldset>
                    <div class="form-row">              
                        <div class="form-group-flex">
                            <div class="form-group">
                               <input type="text" name="password" placeholder="Votre Mot de Passe" />
                            </div>
                            <?php if (!empty($erreur_password)): ?>
                                         <div class="error"><?php echo $erreur_password; ?></div>
                                <?php endif ?>
                            <div class="form-group">
                                <input type="text" name="confirm_password" placeholder="Confirmez Mot de Passe" />
                            </div>
                            <?php if (!empty($erreur_confirm_password)): ?>
                                         <div class="error"><?php echo $erreur_confirm_password; ?></div>
                            <?php endif ?>
                            
                        </div>
                    </div>
                </fieldset>
 
                <h3>
                    Votre Adresse
                </h3>
              <fieldset>
                    <div class="form-row">
                     <div class="form-file">
                            <input type="file" class="inputfile" name="your_picture" id="your_picture"  onchange="readURL(this);" data-multiple-caption="{count} files selected" multiple />
                             
                        </div>                   
                        <div class="form-group-flex">
                             
                            <div class="form-group">
                                <input type="text" name="ville" value="<?php echo isset($_POST['ville'])?$_POST['ville']:$_SESSION['user']['ville']; ?>" placeholder="Ville de Résidence" />
                            </div>
                            <div class="form-group">
                                <input type="email" name="email" value="<?php echo isset($_POST['email'])?$_POST['email']:$_SESSION['user']['email']; ?>" id="email" placeholder="Email" />
                            </div>
                        </div>
                    </div>
                </fieldset>
            </form>
                  <h2 style="margin-top:-100px">Mes achats : </h2 >
      
                                                        <table>
                                                          <thead>
                                                              <tr>
                                                                  <th>N° commande</th>
                                                                  <th>Date</th>
                                                                  <th>Montant</th>
                                                                  <th>Txn_id</th>
                                                                  <th>Actions</th>
                                                              </tr>
                                                          </thead>
                                                          <tbody>
                                                              <?php foreach ($orders as $order): ?>
                                                                <tr>
                                                                  <td><?php echo $order->id ?></td>
                                                                  <td><?php echo $order->created; ?></td>
                                                                  <td><?php echo $order->amount; ?></td>
                                                                  <td><?php echo $order->txn_id; ?></td>
                                                                  <td>
                                                                    <a href="editOrder.php?id=<?php echo $order->id; ?>"  class="edit"></a>
                                                                    <a href="pdfOrder.php?id=<?php echo $order->id; ?>"  class="pdf"></a>
                                                                  </td>
                                                              </tr>
                                                              <?php endforeach ?>
                                                          </tbody>
                                                        </table>
 
 
 
        </div>
 
    </div>
 
    <!-- JS -->
    <script src="vendor/jquery/jquery.min.js"></script>
    <script src="vendor/jquery-validation/dist/jquery.validate.min.js"></script>
    <script src="vendor/jquery-validation/dist/additional-methods.min.js"></script>
    <script src="vendor/jquery-steps/jquery.steps.min.js"></script>
    <script src="js/profil.js"></script>
</body>
</html>


2) Db.php

<?php
 
/**
* Gestion de la base de données
*/
class Db{
     
    private $host=HOST;
    private $name=DBNAME;
    private $user=USER;
    private $pass=PWD;
 
    private $connexion;
 
    function __construct($host=null,$name=null,$user=null,$pass=null){
         
        if($host != null){
            $this->host = $host;
            $this->name = $name;
            $this->user = $user;
            $this->pass = $pass;
        }
 
        try{
 
            $this->connexion = new PDO('mysql:host='.$this->host.';dbname='.$this->name,
                $this->user,$this->pass,array(
                    1002 =>'SET NAMES UTF8',
                    PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING
                    ));
            $this->connexion->exec('SET NAMES utf8');
//PDO::MYSQL_ATTR_INIT_COMMAND
        }catch (PDOException $e){
            //echo 'Erreur : Impossible de se connecter  à la BD !';die();
            echo $e->getMessage();
        }
    }
 
    /* requete */
 
    public function query($sql , $data=array()){
        $req = $this->connexion->prepare($sql);
        $req->execute($data);
        return $req->fetchAll(PDO::FETCH_OBJ);
    }
 
    public function tquery($sql , $data=array()){
        $req = $this->connexion->prepare($sql);
        $req->execute($data);
        return $req->fetchAll(PDO::FETCH_ASSOC);
    }
 
 
    public function insert($sql , $data=array()){
        $req = $this->connexion->prepare($sql);
        $nb=$req->execute($data, $photo);
        return $nb;
    }
 
    public function uniqueEmail($email){
        $req = $this->connexion->prepare('SELECT count(*) as nbre from users WHERE email=:email limit 1');
        $req->execute(array('email'=>$email));
 
        $reponse = $req->fetchAll(PDO::FETCH_ASSOC);
        return $reponse[0]['nbre'];
 
    }
 
}


3) auth.php

<?php 

/**
* Auth
*/
class Auth{
	
	public static function islog($db){
		if(isset($_SESSION['user']) && isset($_SESSION['user']['email']) &&  isset($_SESSION['user']['photo']) && isset($_SESSION['user']['password'])){

			$data =array(
				'email'=>$_SESSION['user']['email'],
				'password'=>$_SESSION['user']['password']
				);
			$photo = ['photo'];
			$sql = 'SELECT * FROM users WHERE email=:email AND password=:password limit 1';
			$req = $db->tquery($sql,$data, $photo);

			if(!empty($req)){
				return true;
			}
		}
		return false;
	}


	public static function hashPassword($pass){

		return sha1(SALT.md5($pass.SALT).sha1(SALT));
	}


	public static function isadmin($db){
		if(isset($_SESSION['user']['role']) && (Auth::hashPassword('admin')  == $_SESSION['user']['role'])){
			return true;
		}
		return false;
	}
}

2 réponses

Messages postés
32322
Date d'inscription
mercredi 22 octobre 2003
Statut
Modérateur
Dernière intervention
6 mai 2021
3 460
Bonjour,

Dans la requête INSERT tu as mis photo =:photo
Mais dans $data .. pas de photo en vue..

A mon avis, à corriger par :
 $data = array(
            'id'=>$_SESSION['user']['id'],
            'nom_prenom' =>$_POST['nom_prenom'],
            'ville'   =>$_POST['ville'],
            'email'   =>$_POST['email'],  
            'password'=>$password,
             'photo' => $filePath.'/'.$filename
            );
        
        $rep = $DB->insert('UPDATE users SET nom_prenom=:nom_prenom,ville=:ville,photo=:photo,email=:email,password=:password WHERE id=:id',$data);
 


Bjr monsieur Jordane
Je vais essayer et vous rendrai compte... Merci

Bonsoir votre solution était la bonne merci