-1

i have an error in my PHP code , undefined variable error while it's already defined before this is the first error :

( ! ) Notice: Undefined variable: utilisateurKore in C:\wamp64\www\myFiles\PHP\views\edit.php on line 16

this is the second error :

this the code wehere the error is :

<?PHP
include "../entities/utilisateur.php";
include "../core/utilisateurCore.php";

if (isset($_GET['pseudo'])){
    $utilisateurKore = new utilisateurCore();
    $result=$utilisateurKore->recupererUser($_GET['pseudo']);
    foreach($result as $row){
        $pseudo=$row['pseudo'];
        $mail=$row['mail'];
        $motdepasse=$row['motdepasse'];
            }
}
if (isset($_POST['modifier'])){
    $utilisateur1=new utilisateur($_POST['pseudo'],$_POST['mail'],$_POST['motdepasse']);
    $utilisateurKore->modifierUser($utilisateur1,$_POST['pseudo']);
}

?>

this is the class of the variable :

<?php 
include "../config.php";
class utilisateurCore{

//edition de profil
  function modifierUser($utilisateur,$pseudo){
    $sql="UPDATE membres SET motdepasse=:motdepasse,mail=:mail WHERE pseudo=:pseudo";

    $db = config::getConnexion(); 
    //$db->setAttribute(PDO::ATTR_EMULATE_PREPARES,false);
try{    
        $req=$db->prepare($sql);
    $motdepasse=$utilisateur->getMotdepasse();
        $mail=$utilisateur->getEmail();

   // $datas = array(':cinn'=>$cinn, ':cin'=>$cin, ':nom'=>$nom,':prenom'=>$prenom,':nbH'=>$nb,':tarifH'=>$tarif);
    $req->bindValue(':mail',$mail);
    $req->bindValue(':motdepasse',$motdepasse);    

            $s=$req->execute();

           // header('Location: index.php');
        }
        catch (Exception $e){
            echo " Erreur ! ".$e->getMessage();
        }

  }
  function recupererUser($pseudo){
    $sql="SELECT * from employe where pseudo=$pseudo";
    $db = config::getConnexion();
    try{
    $liste=$db->query($sql);
    return $liste;
    }
        catch (Exception $e){
            die('Erreur: '.$e->getMessage());
        }
  }
?>
CoderTn
  • 985
  • 2
  • 22
  • 49
  • the second error : ( ! ) Fatal error: Call to a member function modifierUser() on null in C:\wamp64\www\myFiles\PHP\views\edit.php on line 16 – CoderTn Mar 20 '18 at 18:10
  • make you you are have the correct file path in your include statement. – Full Stack Alien Mar 20 '18 at 18:12
  • the first error is solved i have defined an other object with the same class , but there is a second error ( ! ) Fatal error: Call to undefined method utilisateurCore::modifierUser() in C:\wamp64\www\myFiles\PHP\views\edit.php on line 17 while this method is already defined in utilisateurCore.php – CoderTn Mar 20 '18 at 18:16
  • You need to specify whether it's a public function, private or protected. The way you are using it you'll want it to be public – Full Stack Alien Mar 20 '18 at 18:18
  • @Jase i have called another function from the same class recupererUtilisateur() and it's detected as a defined function . – CoderTn Mar 20 '18 at 18:27

1 Answers1

1

$utilisateurKore is only defined when the first if condition matches (isset($_GET['pseudo'])). If the first condition does NOT match, but the second does, you will get this error.

you could either move the second condition (isset($_POST['modifier'])) into the code block of the first condition or set / initialize $utilisateurKore with a default value first.

cypherabe
  • 2,562
  • 1
  • 20
  • 35
  • the modifierUser() function is still undefined here : modifierUser($utilisateur1,$pseudo); } ?> – CoderTn Mar 20 '18 at 18:52