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 :

remplir les données à partir d'un formulaire


Sujet :

Langage PHP

  1. #1
    Nouveau membre du Club
    Inscrit en
    Janvier 2008
    Messages
    38
    Détails du profil
    Informations forums :
    Inscription : Janvier 2008
    Messages : 38
    Points : 33
    Points
    33
    Par défaut remplir les données à partir d'un formulaire
    salut les amis.
    j'ai une base de donnée appelée: GestionDePaie contienne une table appelée Salaries.
    je veux remplir les données d'un salarié à l'aide d'un formulaire html (voir cette image):
    http://i40.servimg.com/u/f40/12/40/95/55/2008-010.jpg
    j'ai essayé d'intégrer le code php avec le code html et j'ai appelé la page de code: donnees.php mais je ne trouve aucune résultat.
    j'ai besoin de votre aide.
    voilà mon code html+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
    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
    <html>
     
    <head>
    <meta http-equiv="Content-Language" content="fr">
    <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>Nouvelle page 1</title>
    <meta name="Microsoft Theme" content="blends 011, default">
    </head>
     
    <body>
     
    <div align="center">
    <center>
    <table border="0" cellspacing="1" style="border-collapse: collapse" width="61%" height="292">
    <tr>
    <td width="23%" height="24"><b>N°immatr</b></td>
    <td width="79%" height="24">:<input type="text" name="i_id" size="20"></td>
    </tr>
    <tr>
    <td width="23%" height="24"><b>Nom</b></td>
    <td width="79%" height="24">:<input type="text" name="n_nom" size="20"></td>
    </tr>
    <tr>
    <td width="23%" height="24"><b>Prénom</b></td>
    <td width="79%" height="24">:<input type="text" name="p_prenom" size="20"></td>
    </tr>
    <tr>
    <td width="23%" height="24"><b>N°CIN</b></td>
    <td width="79%" height="24">:<input type="text" name="c_cin" size="20"></td>
    </tr>
    <tr>
    <td width="23%" height="20"><b>Sit.Familiale</b></td>
    <td width="79%" height="20">:<select size="1" name="s_sit">
    <option>Célibataire</option>
    <option>Marié</option>
    </select></td>
    </tr>
    <tr>
    <td width="23%" height="24"><b>Adresse</b></td>
    <td width="79%" height="24">:<input type="text" name="a_adresse" size="55"></td>
    </tr>
    <tr>
    <td width="23%" height="24"><b>Code Postal</b></td>
    <td width="79%" height="24">:<input type="text" name="c_postal" size="12"></td>
    </tr>
    <tr>
    <td width="23%" height="24"><b>Ville</b></td>
    <td width="79%" height="24">:<input type="text" name="v_ville" size="20"></td>
    </tr>
    <tr>
    <td width="23%" height="24"><b>Téléphone</b></td>
    <td width="79%" height="24">:<input type="text" name="t_tele" size="20"></td>
    </tr>
    <tr>
    <td width="23%" height="24"><b>E-mail</b></td>
    <td width="79%" height="24">:<input type="text" name="e_email" size="29"></td>
    </tr>
    <tr>
    <td width="23%" height="24"><b>Emploi</b></td>
    <td width="79%" height="24">:<select size="1" name="$e_emploi">
    <option>Maçon</option>
    <option>Ouvrier</option>
    <option>Soudeur</option>
    <option>Ferrailleur</option>
    <option>Gardien</option>
    </select></td>
    </tr>
    <tr>
    <td width="23%" height="27"><b>État</b></td>
    <td width="79%" height="27">:<select size="1" name="e_etat">
    <option>Provisoire</option>
    <option>Permanent</option>
    </select></td>
    </tr>
    <tr>
    <td width="23%" height="29"><b>Entré le</b></td>
    <td width="79%" height="29">:<input type="text" name="e_entre" size="14"></td>
    </tr>
    <tr>
    <td width="23%" height="29">&nbsp;</td>
    <td width="79%" height="29">&nbsp;<form method="POST" action="donnees.php">
    <!--webbot bot="SaveResults" U-File="_private/form_results.csv" S-Format="TEXT/CSV" S-Label-Fields="TRUE" --><p>
    <input type="submit" value="Envoyer" name="B1"></p>
    </form>
    </td>
    </tr>
    </table>
    </center>
    </div>
    <p>&nbsp;</p>
     
     
    <?
    //récupération et traitement des valeurs :
    $id=$i_id;
    $nom=$n_nom;
    $prenom=$p_prenom;
    $cin=$c_cin;
    $sit=$s_sit;
    $adresse=$a_adresse;
    $Codepostal=$c_postal;
    $ville=$v_ville;
    $tele=$t_tele;
    $email=$e_email;
    $emploi=$e_emploi;
    $etat=$e_etat;
    $entre=$e_entre;
     
    mysql_connect("localhost","root","");
    mysql_select_db("GestionDePaie");
     
    // On ajoute une entrée avec mysql_query
    mysql_query("INSERT INTO salaries VALUES('$id', '$nom', '$prenom', '$cin','$sit','$adresse','$codepostal','$ville','$tele','$email','$emploi','$etat','$entre')");
    ?>
    </body>
    </html>

  2. #2
    Modératrice
    Avatar de Celira
    Femme Profil pro
    Développeuse PHP/Java
    Inscrit en
    Avril 2007
    Messages
    8 633
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 39
    Localisation : France

    Informations professionnelles :
    Activité : Développeuse PHP/Java
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2007
    Messages : 8 633
    Points : 16 372
    Points
    16 372
    Par défaut
    Un message d'erreur ? Un echo de la requête à nous donner ?
    Tu utilises register_globals pour récupérer les données de ton formulaire ? et je n'ai pas vu les balise <form> ....

  3. #3
    Nouveau membre du Club
    Inscrit en
    Janvier 2008
    Messages
    38
    Détails du profil
    Informations forums :
    Inscription : Janvier 2008
    Messages : 38
    Points : 33
    Points
    33
    Par défaut
    Je vous remercie melle"celira".
    premièrement je vous rappel que je suis débutant en php, doc svp patientez avec moi.
    non, il n y a pas de message affiché.
    quand je remplis les données dans les formulaires et je clique sur envoyer, les formulaires deviennent vide, mais rien ne change dans la base de données.
    question:
    1) qu'est ce que:register_globals??
    2) où je peux mettre les balises:<form>...?
    merci

  4. #4
    Membre du Club Avatar de Archibald_Teepo
    Profil pro
    Étudiant
    Inscrit en
    Mai 2008
    Messages
    102
    Détails du profil
    Informations personnelles :
    Âge : 32
    Localisation : France, Seine et Marne (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2008
    Messages : 102
    Points : 66
    Points
    66
    Par défaut
    Tu dois mettre les balises <form> entre tout tes formulaires.
    Comme ceci par exemple:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    <form method="post" name="nom_du_formulaire" action="tapage.php">
     
     
     
    <u><b><label>Blabla</label></b></u> : 			<input name="test" type="text" size="51">
    <u><b><label>Blabla</label></b></u> : 			<input name="test" type="text" size="51">
     
     
    	<input type="submit" value="Envoyer" />
    </form>
    Le "action" dans le <form> sert à indiquer où se trouve les requêtes à effectuer, en gros tu met la page ou t'as taper tes requêtes SQL.

    Aussi, ce n'est pas comme ça que l'on converti des POST:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    $e_entre=$e_entre;
    Mais comme ça :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    $e_entre = $_POST['e_entre'];

  5. #5
    Nouveau membre du Club
    Inscrit en
    Janvier 2008
    Messages
    38
    Détails du profil
    Informations forums :
    Inscription : Janvier 2008
    Messages : 38
    Points : 33
    Points
    33
    Par défaut
    merci mon frère Archibald. j'ai modifié un peux mon code, mais à propos les balises <form> je trouve encore des difficultés pour les mettes dans leurs places.
    est ce que vous pouver modifier un peux mon code? seulement un éxemple de deux formulaire. vous avez tous les informations: Nom de la base, la table la page de code.
    voilà mon code:
    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
    <html>
     
    <head>
    <meta http-equiv="Content-Language" content="fr">
    <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>Nouvelle page 1</title>
    <meta name="Microsoft Theme" content="blends 011, default">
    </head>
     
    <body>
     
    <div align="center">
      <center>
      <table border="0" cellspacing="1" style="border-collapse: collapse" width="61%" height="292">
        <tr>
          <td width="23%" height="24"><b>N°immatr</b></td>
          <td width="79%" height="24">:<input type="text" name="i_id" size="20"></td>
        </tr>
        <tr>
          <td width="23%" height="24"><b>Nom</b></td>
          <td width="79%" height="24">:<input type="text" name="n_nom" size="20"></td>
        </tr>
        <tr>
          <td width="23%" height="24"><b>Prénom</b></td>
          <td width="79%" height="24">:<input type="text" name="p_prenom" size="20"></td>
        </tr>
        <tr>
          <td width="23%" height="24"><b>N°CIN</b></td>
          <td width="79%" height="24">:<input type="text" name="c_cin" size="20"></td>
        </tr>
        <tr>
          <td width="23%" height="20"><b>Sit.Familiale</b></td>
          <td width="79%" height="20">:<select size="1" name="s_sit">
          <option>Célibataire</option>
          <option>Marié</option>
          </select></td>
        </tr>
        <tr>
          <td width="23%" height="24"><b>Adresse</b></td>
          <td width="79%" height="24">:<input type="text" name="a_adresse" size="55"></td>
        </tr>
        <tr>
          <td width="23%" height="24"><b>Code Postal</b></td>
          <td width="79%" height="24">:<input type="text" name="c_postal" size="12"></td>
        </tr>
        <tr>
          <td width="23%" height="24"><b>Ville</b></td>
          <td width="79%" height="24">:<input type="text" name="v_ville" size="20"></td>
        </tr>
        <tr>
          <td width="23%" height="24"><b>Téléphone</b></td>
          <td width="79%" height="24">:<input type="text" name="t_tele" size="20"></td>
        </tr>
        <tr>
          <td width="23%" height="24"><b>E-mail</b></td>
          <td width="79%" height="24">:<input type="text" name="e_email" size="29"></td>
        </tr>
        <tr>
          <td width="23%" height="24"><b>Emploi</b></td>
          <td width="79%" height="24">:<select size="1" name="e_emploi">
          <option>Maçon</option>
          <option>Ouvrier</option>
          <option>Soudeur</option>
          <option>Ferrailleur</option>
          <option>Gardien</option>
          </select></td>
        </tr>
        <tr>
          <td width="23%" height="27"><b>État</b></td>
          <td width="79%" height="27">:<select size="1" name="e_etat">
          <option>Provisoire</option>
          <option>Permanent</option>
          </select></td>
        </tr>
        <tr>
          <td width="23%" height="29"><b>Entré le</b></td>
          <td width="79%" height="29">:<input type="text" name="e_entre" size="14"></td>
        </tr>
        <tr>
          <td width="23%" height="29">&nbsp;</td>
          <td width="79%" height="29">&nbsp;<form method="POST" action="donnees.php">
            <!--webbot bot="SaveResults" U-File="_private/form_results.csv" S-Format="TEXT/CSV" S-Label-Fields="TRUE" --><p>
            <input type="submit" value="Envoyer" name="B1"></p>
          </form>
          </td>
        </tr>
      </table>
      </center>
    </div>
    <p>&nbsp;</p>
     
     
    <?php
    //récupération et traitement des valeurs :
    $id = $_POST['$i_id'];
    $nom = $_POST['$n_nom'];
    $prenom = $_POST['$p_prenom'];
    $cin = $_POST['$c_cin'];
    $sit = $_POST['$s_sit'];
    $adresse = $_POST['$a_adresse'];
    $codepostal = $_POST['$c_postal'];
    $ville = $_POST['$v_ville'];
    $tele = $_POST['$t_tele'];
    $email = $_POST['$e_email'];
    $emploi = $_POST['$e_emploi'];
    $etat = $_POST['$e_etat'];
    $entre = $_POST['$e_entre'];
     
    mysql_connect("localhost","root","");
    mysql_select_db("GestionDePaie");
     
    // On ajoute une entrée avec mysql_query
    mysql_query("INSERT INTO salaries VALUES('$id', '$nom', '$prenom', '$cin','$sit','$adresse','$codepostal','$ville','$tele','$email','$emploi','$etat','$entre')");
    //mysql_query("INSERT INTO salaries VALUES('".$id."', '".$nom."', '".$prenom."', '".$cin."','".$sit."','".$adresse."','".$codepostal."','".$ville."','".$tele."','".$email."','".$emploi."','".$etat."','".$entre."')");
    ?>
    </body>
    </html>

  6. #6
    Membre du Club Avatar de Archibald_Teepo
    Profil pro
    Étudiant
    Inscrit en
    Mai 2008
    Messages
    102
    Détails du profil
    Informations personnelles :
    Âge : 32
    Localisation : France, Seine et Marne (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2008
    Messages : 102
    Points : 66
    Points
    66
    Par défaut
    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
     
    <html>
     
    <head>
    <meta http-equiv="Content-Language" content="fr">
    <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>Nouvelle page 1</title>
    <meta name="Microsoft Theme" content="blends 011, default">
    </head>
     
    <body>
     <form method="POST" name="formulaire" action="donnees.php">
    <div align="center">
      <center>
      <table border="0" cellspacing="1" style="border-collapse: collapse" width="61%" height="292">
        <tr>
          <td width="23%" height="24"><b>N°immatr</b></td>
          <td width="79%" height="24">:<input type="text" name="i_id" size="20"></td>
        </tr>
        <tr>
          <td width="23%" height="24"><b>Nom</b></td>
          <td width="79%" height="24">:<input type="text" name="n_nom" size="20"></td>
        </tr>
        <tr>
          <td width="23%" height="24"><b>Prénom</b></td>
          <td width="79%" height="24">:<input type="text" name="p_prenom" size="20"></td>
        </tr>
        <tr>
          <td width="23%" height="24"><b>N°CIN</b></td>
          <td width="79%" height="24">:<input type="text" name="c_cin" size="20"></td>
        </tr>
        <tr>
          <td width="23%" height="20"><b>Sit.Familiale</b></td>
          <td width="79%" height="20">:<select size="1" name="s_sit">
          <option>Célibataire</option>
          <option>Marié</option>
          </select></td>
        </tr>
        <tr>
          <td width="23%" height="24"><b>Adresse</b></td>
          <td width="79%" height="24">:<input type="text" name="a_adresse" size="55"></td>
        </tr>
        <tr>
          <td width="23%" height="24"><b>Code Postal</b></td>
          <td width="79%" height="24">:<input type="text" name="c_postal" size="12"></td>
        </tr>
        <tr>
          <td width="23%" height="24"><b>Ville</b></td>
          <td width="79%" height="24">:<input type="text" name="v_ville" size="20"></td>
        </tr>
        <tr>
          <td width="23%" height="24"><b>Téléphone</b></td>
          <td width="79%" height="24">:<input type="text" name="t_tele" size="20"></td>
        </tr>
        <tr>
          <td width="23%" height="24"><b>E-mail</b></td>
          <td width="79%" height="24">:<input type="text" name="e_email" size="29"></td>
        </tr>
        <tr>
          <td width="23%" height="24"><b>Emploi</b></td>
          <td width="79%" height="24">:<select size="1" name="e_emploi">
          <option>Maçon</option>
          <option>Ouvrier</option>
          <option>Soudeur</option>
          <option>Ferrailleur</option>
          <option>Gardien</option>
          </select></td>
        </tr>
        <tr>
          <td width="23%" height="27"><b>État</b></td>
          <td width="79%" height="27">:<select size="1" name="e_etat">
          <option>Provisoire</option>
          <option>Permanent</option>
          </select></td>
        </tr>
        <tr>
          <td width="23%" height="29"><b>Entré le</b></td>
          <td width="79%" height="29">:<input type="text" name="e_entre" size="14"></td>
        </tr>
        <tr>
          <td width="23%" height="29">&nbsp;</td>
          <td width="79%" height="29">&nbsp;
            <!--webbot bot="SaveResults" U-File="_private/form_results.csv" S-Format="TEXT/CSV" S-Label-Fields="TRUE" --><p>
            <input type="submit" value="Envoyer" name="B1"></p>
          </form>
          </td>
        </tr>
      </table>
      </center>
    </div>
    <p>&nbsp;</p>
     
     
    <?php
    //récupération et traitement des valeurs :
    $id = $_POST['i_id'];
    $nom = $_POST['n_nom'];
    $prenom = $_POST['p_prenom'];
    $cin = $_POST['c_cin'];
    $sit = $_POST['s_sit'];
    $adresse = $_POST['a_adresse'];
    $codepostal = $_POST['c_postal'];
    $ville = $_POST['v_ville'];
    $tele = $_POST['t_tele'];
    $email = $_POST['e_email'];
    $emploi = $_POST['e_emploi'];
    $etat = $_POST['e_etat'];
    $entre = $_POST['e_entre'];
     
    $connexion = mysql_connect("localhost","root","");
    $base = mysql_select_db("GestionDePaie");
     
    // On ajoute une entrée avec mysql_query
    $requete = mysql_query("INSERT INTO salaries VALUES('$id', '$nom', '$prenom', '$cin','$sit','$adresse','$codepostal','$ville','$tele','$email','$emploi','$etat','$entre')");
    //mysql_query("INSERT INTO salaries VALUES('".$id."', '".$nom."', '".$prenom."', '".$cin."','".$sit."','".$adresse."','".$codepostal."','".$ville."','".$tele."','".$email."','".$emploi."','".$etat."','".$entre."')");
    ?>
    </body>
    </html>
    Petite précision, t'avais oublier d'enlever les "$" dans les POST.
    Tu t'es quand même un peu compliquer la vie à faire tout ses tableau. Y avait plus simple.

    Je pense que ça devrait aller là

  7. #7
    Nouveau membre du Club
    Inscrit en
    Janvier 2008
    Messages
    38
    Détails du profil
    Informations forums :
    Inscription : Janvier 2008
    Messages : 38
    Points : 33
    Points
    33
    Par défaut

    meeeerrrrrrrrciiii bp "Archibald_Teepo". ça marche très bien.
    je m'excuse pour le dérangement.

  8. #8
    Membre du Club Avatar de Archibald_Teepo
    Profil pro
    Étudiant
    Inscrit en
    Mai 2008
    Messages
    102
    Détails du profil
    Informations personnelles :
    Âge : 32
    Localisation : France, Seine et Marne (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2008
    Messages : 102
    Points : 66
    Points
    66
    Par défaut
    Pas de problème !
    C'était avec plaisir !

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

Discussions similaires

  1. [XL-2007] Remplir une base de données à partir d'un formulaire
    Par BtjpsspgrW dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 04/09/2014, 11h47
  2. Réponses: 3
    Dernier message: 06/07/2006, 18h49
  3. [C#/SqlServer 2005] Comment remplir une DB à partir d'un formulaire ?
    Par Clarissa2006 dans le forum Windows Forms
    Réponses: 20
    Dernier message: 22/06/2006, 16h10
  4. Filtrer sur les données vides dans un formulaire
    Par jevany dans le forum Access
    Réponses: 7
    Dernier message: 29/05/2006, 08h50
  5. Réuperer les données à partir d'un fichier de log
    Par Oberown dans le forum MS SQL Server
    Réponses: 3
    Dernier message: 31/10/2005, 10h08

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