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 :

Insérer valeur de la liste déroulante


Sujet :

Langage PHP

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Femme Profil pro
    Stagiaire
    Inscrit en
    Août 2009
    Messages
    148
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations professionnelles :
    Activité : Stagiaire
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2009
    Messages : 148
    Par défaut Insérer valeur de la liste déroulante
    Bonjour,

    je veux inserer les donnees de la formaulaire a la base de donnees ts ca marche sauf la valeur de liste deroulante,je trouve dans le champ de la liste numero 0 voila mon code.

    page de la formulaire:
    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
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    <!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=utf-8" />
    <title>site annonce</title>
    </head>
    <body>
    <div>
    <form action="ajouter_annonce.php"  method="post" enctype="multipart/form-data">
        <p>
          <label><strong> &nbsp;&nbsp;&nbsp;&nbsp;Annonce:<br/>
            <br />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Categorie :  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong>
            <select name="categorie">
              <option>Emploi</option>
              <option>Stage</option>
            </select>
          </label>
          <label>      </label>
        </p>
    <p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pays:</strong>
    <? include('connection.php');
       echo'<select size=1 name="nom_pays">'."\n";
       echo'<option value="-1">-- pays--</option>'."\n";
       $resul=mysql_query("select nom_pays from pays");
       while($dat=mysql_fetch_array($resul)){
     
       echo'<option value="'.$dat[0].'">'.$dat['nom_pays'];
       echo'</option>'."\n";
       }
       echo'</select>'."\n";
       mysql_close();
       ?>
        </p>
        <p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ville:</strong>
    <? include('connection.php');
       echo'<select size=1 name="nom_ville">'."\n";
       echo'<option value="-1">-- ville--</option>'."\n";
       $result=mysql_query("select nom_ville from ville");
       while($data=mysql_fetch_array($result)){
     
       echo'<option value="'.$data[0].'">'.$data['nom_ville'];
       echo'</option>'."\n";
       }
       echo'</select>'."\n";
       mysql_close();
       ?>
        </p>
        <p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Code postal:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </strong>
          <input type="text" name="code_postal" />
        </p>
        <p>
          <label><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;domaine &nbsp;&nbsp;:&nbsp;</strong></label>
          <? include('connection.php');
       echo'<select size=1 name="domaine">'."\n";
       echo'<option value="-1">-- domaine--</option>'."\n";
       $res=mysql_query("select domaine from domaine");
       while($da=mysql_fetch_array($res)){
     
       echo'<option value="'.$da[0].'">'.$da['domaine'];
       echo'</option>'."\n";
       }
       echo'</select>'."\n";
       mysql_close();
       ?>
        </p>
        <p>
          <label><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fonction&nbsp;&nbsp;:&nbsp;</strong>
            <? include('connection.php');
       echo'<select size=1 name="fonction">'."\n";
       echo'<option value="-1">-- fonction--</option>'."\n";
       $res=mysql_query("select fonction from fonction");
       while($da=mysql_fetch_array($res)){
     
       echo'<option value="'.$da[0].'">'.$da['fonction'];
       echo'</option>'."\n";
       }
       echo'</select>'."\n";
       mysql_close();
       ?>
          </label>
        </p>
        <p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;Titre annonce &nbsp;&nbsp;:&nbsp;</strong>
          <input type="text" name="titre_annonce" />
        </p>
        <p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong><strong>&nbsp;&nbsp; Description  &nbsp;&nbsp; &nbsp;&nbsp; </strong> :</p>
        <p><strong>&nbsp;&nbsp; </strong><strong>&nbsp;&nbsp; </strong><strong>&nbsp;&nbsp; </strong><strong>&nbsp;&nbsp; </strong><strong>&nbsp;&nbsp; </strong><strong>&nbsp;&nbsp; </strong><strong>&nbsp;&nbsp; </strong><strong>&nbsp;&nbsp; </strong><strong>&nbsp;&nbsp; </strong><strong>&nbsp;&nbsp; </strong><strong>&nbsp;&nbsp; </strong><strong>&nbsp;&nbsp; </strong><strong>&nbsp;&nbsp; </strong>
      <textarea name="description"  cols="45" rows="5"></textarea>
        </p>
        <p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong><strong>&nbsp;&nbsp; </strong><strong>Raison social &nbsp;&nbsp;:&nbsp;</strong>
          <input type="text" name="raison_sociale" />
        </p>
        <p>
          <label><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nom &nbsp;&nbsp;:&nbsp;</strong>
          <strong>&nbsp;&nbsp;</strong><strong>&nbsp;&nbsp;</strong><strong>&nbsp;&nbsp;</strong>
          <input type="text" name="nom" />
          </label>
        </p>
        <p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong>
          <input type="hidden" name="id_user" />
        </p>
        <p>
          <label><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Tel &nbsp;&nbsp;:&nbsp;</strong><strong>&nbsp;&nbsp;</strong><strong>&nbsp;&nbsp;</strong><strong>&nbsp;&nbsp;</strong><strong>&nbsp;&nbsp;</strong><strong>&nbsp;&nbsp;</strong><strong>&nbsp;&nbsp;</strong><strong>&nbsp;&nbsp;</strong><strong>&nbsp;&nbsp;</strong><strong>&nbsp;&nbsp;</strong>
            <input type="text" name="tel" />
          </label>
        </p>
        <p>
        <label><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong></label>
        <strong>Image:</strong>
        <strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </strong><strong>&nbsp;&nbsp;&nbsp;</strong>
        <input type="file" name="monfichier" />
        </p>
        <p>
         <label><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong></label>
        </p>
        <p>
     
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <input type="submit" name="ok"  value="Enregistrer" />
        </p>
        <p>&nbsp;</p>
      </form>
    </div>
    </body>
    </html>
    page ajouter.php:

    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
    <? include("connection.php");
    if(isset($_POST['titre_annonce'])and isset($_POST['description'])){
    $categorie=$_POST['categorie'];
    $id_ville=$_POST['nom_ville'];
    $code_postal=$_POST['code_postal'];
    $id_domaine=$_POST['domaine'];
    $id_fonction=$_POST['fonction'];
    $description=$_POST['description'];
    $titre_annonce=$_POST['titre_annonce'];
    $raison_sociale=$_POST['raison_sociale'];
    $nom=$_POST['nom'];
    $tel=$_POST['tel'];
    //$valider=$_POST['valider'];
     
     $repertoireDestination = "image_annonce/";
        $nomDestination        = $_FILES["monfichier"]["name"];
        if (is_uploaded_file($_FILES["monfichier"]["tmp_name"])) {
            if (rename($_FILES["monfichier"]["tmp_name"],
                       $repertoireDestination.$nomDestination)) {
                echo "fichier bien telecharger";
            } 
        } else {
           echo "Le fichier n'a pas été uploadé (trop gros ?)";
        }
    $a=    "admin/".$repertoireDestination.$nomDestination;
     
     
    if($description==''){ ?> <script language="JavaScript">alert("Vous devez remplir tous les champs");</script>
    <? 
    } else {
     
    mysql_query("INSERT INTO annonces VALUES (
    '', '$categorie', '$id_ville', '$code_postal', '$id_domaine', '$id_fonction','$titre_annonce', '$description','$raison_sociale', '$nom', '$tel','$nomDestination','non')");
     
    echo("l ajout effectuer avec succes");}
     
    mysql_close();
    }
    ?>
    merci d'avance

  2. #2
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Par défaut
    Bonjour,
    Les options de ton select n'ont pas de value.
    <select name="categorie">
    <option>Emploi</option>
    <option>Stage</option>
    </select>
    A+.

  3. #3
    Membre confirmé
    Femme Profil pro
    Stagiaire
    Inscrit en
    Août 2009
    Messages
    148
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations professionnelles :
    Activité : Stagiaire
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2009
    Messages : 148
    Par défaut
    merci,mais categorie ca marche le probleme dans la les listes qui sont recuperer les donnees a partir de la base de donnees (liste ville).

    n'hesitez pas de m'aider

  4. #4
    Membre confirmé
    Femme Profil pro
    Stagiaire
    Inscrit en
    Août 2009
    Messages
    148
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations professionnelles :
    Activité : Stagiaire
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2009
    Messages : 148
    Par défaut
    voila le code de liste ville:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    <p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ville:</strong>
    <? include('connection.php');
       echo'<select size=1 name="nom_ville">'."\n";
       echo'<option value="-1">-- ville--</option>'."\n";
       $result=mysql_query("select nom_ville from ville");
       while($data=mysql_fetch_array($result)){
     
       echo'<option value="'.$data[0].'">'.$data['nom_ville'];
       echo'</option>'."\n";
       }
       echo'</select>'."\n";
       mysql_close();
       ?>

  5. #5
    Membre confirmé
    Femme Profil pro
    Stagiaire
    Inscrit en
    Août 2009
    Messages
    148
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations professionnelles :
    Activité : Stagiaire
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2009
    Messages : 148
    Par défaut
    merci j'ai trouvé le probleme maintenant ca marche ,je dois ajouter id_ville dans la requete select :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    <? include('connection.php');
       echo'<select size=1 name="nom_ville">'."\n";
       echo'<option value="-1">-- ville--</option>'."\n";
       $result=mysql_query("select id_ville,nom_ville from ville");
       while($data=mysql_fetch_array($result)){
     
       echo'<option value="'.$data[0].'">'.$data['nom_ville'];
       echo'</option>'."\n";
       }
       echo'</select>'."\n";
       mysql_close();
       ?>:
    ccool:

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

Discussions similaires

  1. Réponses: 1
    Dernier message: 06/03/2013, 19h27
  2. Réponses: 1
    Dernier message: 29/12/2012, 23h26
  3. valeur d'un liste déroulante à insérer
    Par adriennoob dans le forum VBA Access
    Réponses: 2
    Dernier message: 24/07/2009, 15h25
  4. Tester les valeur d'une liste déroulante
    Par st0nky dans le forum Langage
    Réponses: 1
    Dernier message: 04/12/2005, 15h52
  5. valeur d'une liste déroulante
    Par leeloo076 dans le forum ASP
    Réponses: 7
    Dernier message: 15/04/2004, 17h11

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