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

Langage PHP Discussion :

Undefined index en php5


Sujet :

Langage PHP

  1. #1
    Futur Membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Avril 2011
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Conseil

    Informations forums :
    Inscription : Avril 2011
    Messages : 12
    Points : 6
    Points
    6
    Par défaut Undefined index en php5
    bonsoir,
    j'ai une grande problème en php5 concernant l'appel d'une fonction dans la valeur d'un formulaire le code est le suivant:
    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
    <?php
    require_once("connexion.php");
    class hotel
    {
    public $Nomhotel;
    public function affinomhotel()
    {
    $Nomhotel1=$_POST['nomhotel'];
    $requete ="select Nomhotel from hotel where Nomhotel LIKE '%$Nomhotel1%'";
    if($result =mysql_query($requete)){
    while($ligne = mysql_fetch_array($result)) { 
    $Nomhotel=$ligne[0];
    echo $Nomhotel;
    }
    }
    }
    }
    $obj =new hotel;
    $obj->affinomhotel();
    ?>
    ce code pour la fonction que je veux l'appeler et voici le code que je fais pour l'appeler:
    Code html : Sélectionner tout - Visualiser dans une fenêtre à part
    <input name="nomhotel" type="text" value ="<?php require_once('recherchernomhotel.php');?>">

    il m'affiche la faute suivante:
    Notice: Undefined index: nomhotel in D:\EasyPHP-5.3.3\www\pfe\recherchernomhotel.php on line 8
    palmerie
    Sauriez-vous m'aider, s'il vous plait ?
    Merci.

  2. #2
    Expert éminent sénior

    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    7 920
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 7 920
    Points : 10 726
    Points
    10 726
    Par défaut
    $_POST['nomhotel'] n'existe pas, verfie bien tes valeurs d'entré

  3. #3
    Membre régulier Avatar de betadev
    Homme Profil pro
    Développeur Web
    Inscrit en
    Octobre 2008
    Messages
    94
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Octobre 2008
    Messages : 94
    Points : 94
    Points
    94
    Par défaut
    Bonjour,

    Apparemment tu as besoin de faire une recherche sur les noms des hotels .
    Bon , voici un petit exemple pour exploiter la class :

    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
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Document sans titre</title>
    </head>
     
    <body>
    <?
    if(isset($_POST['nomhotel']))
    {
    	require_once("connexion.php");
    	class hotel
    	{
    		public $Nomhotel;
    		public function affinomhotel()
    		{
    			$Nomhotel1=$_POST['nomhotel'];
    			$requete ="select Nomhotel from hotel where Nomhotel LIKE '%$Nomhotel1%'";
    			if($result =mysql_query($requete)){
    				while($ligne = mysql_fetch_array($result)) { 
    					$Nomhotel=$ligne[0];
    					echo $Nomhotel;
    				}
    			}
    		}
    	}
     
    	$obj =new hotel;
    	$obj->affinomhotel();
    }
    ?>
    <form id="form1" name="form1" method="post" action="">
        <input name="nomhotel" type="text" />
        <input type="submit" name="Submit" value="Envoyer" />
    </form>
    </body>
    </html>
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    La programmation ce n'est pas de la magie , c'est simplement de la logique

  4. #4
    Membre habitué Avatar de omar24
    Homme Profil pro
    Inscrit en
    Septembre 2010
    Messages
    159
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Septembre 2010
    Messages : 159
    Points : 172
    Points
    172
    Par défaut
    Je pense que ta classe est un peu mal conçue !!!
    en tout cas essaye de donner un argument à la fonction affinomhotel($nomhotel) et quand tu veux l'utiliser fais comme ça affinomhotel($_POST['nomhotel']) à condition que tu sois sur d'avoir envoyer un nomhotel dans ta requete post et que tu aies dèjà un objet de type Hotel.

Discussions similaires

  1. erreur undefined index
    Par istreen dans le forum Langage
    Réponses: 8
    Dernier message: 06/01/2006, 13h09
  2. [Librairies] PHPMVC : Undefined index
    Par Benat64 dans le forum Bibliothèques et frameworks
    Réponses: 2
    Dernier message: 30/12/2005, 09h27
  3. [Noob] Undefined index: id
    Par Devil666 dans le forum Langage
    Réponses: 4
    Dernier message: 08/12/2005, 13h00
  4. Undefined index
    Par sebduduf dans le forum Langage
    Réponses: 5
    Dernier message: 02/11/2005, 12h13
  5. Erreur de "Undefined index" sur HTTP_REFERER
    Par guy2004 dans le forum Langage
    Réponses: 4
    Dernier message: 12/10/2005, 12h21

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