valider un formulaire
Hors ligneDekec Le 16/04/2008 à 15:42 Profil de Dekec Configuration de Dekec

bonjour
j'ai un probleme concernant mon formulaire. je m'explique:
j'ai ecrit mon code php pour valider mon formulaire et voila la réponse. merci pour votre aide.
mon code :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>connect</title>
</head>

<body>
<?php
require('connexion.php');

//on recupere toutes les info provenant du formulaire
$matricule=($_POST['matricule']);
$login=($_POST['login']);
$motdepasse=($_POST['motdepasse']);
$poste=($_POST['poste']);
$nom=($_POST['nom']);
$prenoms=($_POST['prenoms']);

//on verifie qu'il y a envoi bien eu un envoi de données.
if($matricule != "" and $login != "" and $motdepasse != "" and $poste != "" and $nom != "" and $prenoms != "")

{

//on enregistre dans la base de données
$sql = "INSER INTO 'agent' VALUES('', '$matricule', '$login', '$motdepasse', '$poste', '$nom', '$prenoms')";
mysql_query($sql) or die ("L'insertion a echouée");

echo '<centre><p> Votre enregistrement a été bien éffectué <p>
<p><a href="agent.php">Agent</a></p>
<p><a href="bd.php">Base de Données</a></p>';

}
else
{
echo'Veuillez remplir tous les champs du formulaire';
}

?>

</body>
</html>

<?
mysql_close();
?>


et voici l'erreur:


Notice: Undefined index: matricule in C:\Program Files\EasyPHP 2.0b1\www\connectagent.php on line 14

Notice: Undefined index: login in C:\Program Files\EasyPHP 2.0b1\www\connectagent.php on line 15

Notice: Undefined index: motdepasse in C:\Program Files\EasyPHP 2.0b1\www\connectagent.php on line 16

Notice: Undefined index: poste in C:\Program Files\EasyPHP 2.0b1\www\connectagent.php on line 17

Notice: Undefined index: nom in C:\Program Files\EasyPHP 2.0b1\www\connectagent.php on line 18

Notice: Undefined index: prenoms in C:\Program Files\EasyPHP 2.0b1\www\connectagent.php on line 19
Veuillez remplir tous les champs du formulaire


merci de votre aide
--
bonjour
Hors ligneKefren Le 16/04/2008 à 16:20 Profil de Kefren Configuration de Kefren

A mon avis ce sont tes variables de $_POST qui sont vides !!!

pour ta verif place le avant de mettre tes données dans d'autres variables :


if(isset($_POST['matricule'],...,$_POST['prenoms']))
{
     echo "tous les champs ne sont pas remplis";
}


Et puis pour etre sur fais les afficher dans un permier temps :


echo $_POST['...'];

Et puis met en forme t message stp, car c'est plus pratique pour lire du code ;)
--
Si les poules traversent juste devant les voitures ... c'est pour aller de l'autre coté de la route !!!
Hors ligneDekec Le 16/04/2008 à 16:25 Profil de Dekec Configuration de Dekec

merci pour la reponse mais, je ne comprend pas la suite
soit plus explicite
--
bonjour
Hors ligneKefren Le 16/04/2008 à 17:02 Profil de Kefren Configuration de Kefren

Tu veux dire quand je te dis d'afficher tes variables '$_POST' ???

Ben tu fais un echo de toutes tes variables '$_POST' pour les afficher sur ta page web, comme ca en entendant de finir ta page tu vois ou les valeurs ne sont pas transmises ;)

ex : <?php echo $_POST['matricule']; ?>

après il n'est peut-être pas nécessaire que tu les affiches toutes, affiche déjà la première car ton erreur doit être répercutée sur les autres variables.

Ca doit être ton formulaire qui ne te transmet pas la valeur de tes variables '$_post'

Essaye ca, vois si tu peux trouver l'erreur sinon montre le code de ton formulaire et correctement présenté stp ;)

Et tant que tu y es, arrange ton premier message ...
--
Si les poules traversent juste devant les voitures ... c'est pour aller de l'autre coté de la route !!!
Hors ligneDekec Le 16/04/2008 à 18:03 Profil de Dekec Configuration de Dekec

ok voici mon code html, il contient les boutons annuler, valider, modifier, fermer, imprimer et ok. chaque bouton refere a un code php.
le bouton valider doit enregistrer les données dasn ma base de données
le bouton modifier doit permettre uen modification dnas la base de données.
voici mon code html:

EDIT antho : tu peux utiliser la balise [code] pour mettre en forme ton code :)


<!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>Agent</title>
</head>

<body>

<form name="form1" id="form1" method="post" action="">
  <table width="751" border="1" align="center">
    <tr>
      <td width="741">
<div align="center"><img src="entete.JPG" width="733" height="120" /></div></td>
    </tr>
    <tr>

      <td><p>&nbsp;</p>
        <p>
&nbsp;</p>
        <p>
&nbsp;</p>
        <table width="556" border="0" align="center">

          <tr>
            <td width="210">
<div align="center">matricule : </div></td>
            <td width="330"><input type="text" name="textfield" /></td>
          </tr>

          <tr>
            <td colspan="2">
&nbsp;</td>
          </tr>

          <tr>
            <td>
<div align="center">login : </div></td>
            <td><input type="text" name="textfield" /></td>
          </tr>

          <tr>
            <td colspan="2">
&nbsp;</td>
          </tr>

          <tr>
            <td>
<div align="center"></div>
              <div align="center">
motdepasse : </div></td>
            <td><input type="text" name="textfield" /></td>
          </tr>

          <tr>
            <td colspan="2">
&nbsp;</td>
          </tr>

          <tr>
            <td>
<div align="center">poste : </div></td>
            <td><input type="text" name="textfield" /></td>
          </tr>

          <tr>
            <td colspan="2">
&nbsp;</td>
          </tr>

          <tr>
            <td>
<div align="center">nom : </div></td>
            <td><input type="text" name="textfield" /></td>
          </tr>

          <tr>
            <td colspan="2">
&nbsp;</td>
          </tr>

          <tr>
            <td>
<div align="center">prenoms : </div></td>
            <td><input type="text" name="textfield" /></td>
          </tr>

        </table>        
        <p>
&nbsp;</p>
        <table width="712" border="0" align="center">

          <tr>
            <td width="112">
<div align="center">
              <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="108" height="34">
                <param name="BGCOLOR" value="" />
                <param name="movie" value="button13.swf" />
                <param name="quality" value="high" />
                <embed src="button13.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="108" height="34" ></embed>
              </object>
</div>
</td>
            <td width="112">
<div align="center">
              <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="108" height="34">
                <param name="BGCOLOR" value="" />
                <param name="movie" value="button14.swf" />
                <param name="quality" value="high" />
                <embed src="button14.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="108" height="34" ></embed>
              </object>
            </div>
</td>
            <td width="112">
<div align="center">
              <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="108" height="34">
                <param name="BGCOLOR" value="" />
                <param name="movie" value="button15.swf" />
                <param name="quality" value="high" />
                <embed src="button15.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="108" height="34" ></embed>
              </object>
            </div>
</td>
            <td width="112">
<div align="center">
              <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="108" height="34">
                <param name="movie" value="button16.swf" />
                <param name="quality" value="high" />
                <embed src="button16.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="108" height="34" ></embed>
              </object>
            </div>
</td>
            <td width="112">
<div align="center">
              <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="108" height="34">
                <param name="movie" value="button17.swf" />
                <param name="quality" value="high" />
                <embed src="button17.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="108" height="34" ></embed>
              </object>
            </div>
</td>
            <td width="112">
<div align="center">
              <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="108" height="34">
                <param name="movie" value="button18.swf" />
                <param name="quality" value="high" />
                <embed src="button18.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="108" height="34" ></embed>
              </object>
            </div>
</td>
          </tr>

        </table>        
        <p>
&nbsp;</p>
        <p>
&nbsp;</p>
        <p>
&nbsp;</p></td>
    </tr>
  </table>

  <p>&nbsp;</p>
</form>
</body>

</html>

merci pour ton aide
--
bonjour
Hors ligneKefren Le 16/04/2008 à 21:15 Profil de Kefren Configuration de Kefren

c normal regarde le "name" de tes input text ...


<td width="210"><div align="center">matricule : </div></td>
            <td width="330"><input type="text" name="textfield" /></td>


ton name sera le nom de ta variable $_POST ou $_GET

donc pour appelé ta variable $_POST['matricule'] il faudra d'abord quelle prenne la valeur...comme ca :


<td width="210"><div align="center">matricule : </div></td>
            <td width="330"><input type="text" name="matricule" /></td>


fais en de même pour les autres ;)

Et puis dreamweaver et flash macromedia c'est tres bien en tout cas pour le code c'est super clair, j'aime bien, mais en mode graphique ... c'est moins top

Apprend plutot à créer tes pages sant graphismes, juste des chose simples et après tu met en page avec des feuilles de style css, et tu verra que ton code sera beaucoup plus clair deja ;)
--
Si les poules traversent juste devant les voitures ... c'est pour aller de l'autre coté de la route !!!
Vous avez résolu votre problème avec VIC ? Faites-le savoir sur les réseaux sociaux !
Vulgarisation-informatique.com
Cours en informatique & tutoriels