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

PHP & Base de données Discussion :

Vérification si un champ est vide et l'ajout


Sujet :

PHP & Base de données

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mars 2008
    Messages
    298
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Mars 2008
    Messages : 298
    Par défaut Vérification si un champ est vide et l'ajout
    Salut bon je travaille avec xhtml et php mont serveur local c'est mysql je suis entrain de realiser une application par web j'ai une bdd nommé Gestion pack Serveur j'ai 3 table Client, pack, est Commande.
    Mon probleme se situe Comment je peux verifier si l'utilisateur a laisser un champs vide ainsi je dois afficher un message qui indique que le champ est videainsi obligatoirement le champs dois etre saisie pour que l'ajout s'exécute dans la table Client.
    bon je me suis servis du if($variable=='')
    voila mon code
    saisie_clt.html
    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
     
    <!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-Language" content="ar-tn">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1256"><title>artisana</title></head><body>
    <div align= "center">
    <form method="POST" action="ecriture_clt.php">
        <table bgcolor="#0000ff" border="0" height="399" width="590" >
     
    <tbody><tr>
           <font size="5">
           <body bgcolor="white" text="black" link="blue" vlink="purple" alink="red" background="../images/bamboo.jpg">
           </font>
           <div align="center"></div>
        <td height="22" colspan="4" bgcolor="#0000cc">
          <p align="center"><font color="#ffffff" size="5"><strong>Inscription Client</strong></font></td>
      </tr>
       <tr>
        <td bgcolor="#0000ff" height="30" width="149" >
          <p align="center"><font color="#ffffff"><strong>Nom Client :</strong></font></p> </td>
       <td bgcolor="#0000ff" colspan="2">
       <p align="left"><input name="nom_clt" type="text" id="nom_clt" size="26" ></td>
     </tr>
     <tr>
        <td bgcolor="#0000ff" height="30" width="149" ><p align="center"><font color="#ffffff"><strong>Company :</strong></font></p> </td>
       <td bgcolor="#0000ff" colspan="2">
       <p align="left"><input name="com_clt" type="text" id="com_clt" size="26" ></td>
     </tr>
     <tr>
        <td bgcolor="#0000ff" height="99" width="149" >
          <p align="center"><font color="#ffffff"><strong> Adresse :</strong></font></p> </td>
       <td bgcolor="#0000ff" colspan="2">
         <p align="left">
           <textarea name="adr_clt" cols="40" rows="4" id="adr_clt"></textarea>
         </td>
     </tr>
      <tr>
      <td bgcolor="#0000ff" width="149"><div align="center"><font color="#ffffff"><strong>Ville :</strong></font></div></td>
       <td bgcolor="#0000ff" height="23" colspan="2"><select name="ville_clt" size="1" id="ville_clt">
         <option value="">---</option>
         <option value="casa" selected="selected">Casablanca</option>
         <option value="rabat">Rabat</option>
         <option value="oujda">Oujda</option>
         <option value="fes">Fes</option>
         <option value="meknes">Meknes</option>
         <option value="tetouan">Tetouane</option>
    	  <option value="jadida">Jadida</option>
    	   <option value="setat">Settat</option>
    	    <option value="temara">Temarra</option>
                      </select></td>
     </tr>
     
    <tr>
          <td bgcolor="#0000ff" height="23" width="149">
          <p align="center"><font color="#ffffff"><strong>T&eacute;l&eacute;phone :</strong></font></p> </td>
       <td bgcolor="#0000ff" colspan="2"><input name="tel_clt" type="text" id="tel_clt" size="26"></td>
      </tr>
     
    <tr>
        <td bgcolor="#0000ff" width="149"><div align="center"><font color="#ffffff"><strong> E-mail :</strong></font></div></td>
     
        <td bgcolor="#0000ff" height="23" colspan="2">
          <p align="left">
            <input name="email_clt" type="text" id="email_clt" size="30">
          </td><td width="1"></p>
       </tr>
     
      <tr>
        <td bgcolor="#0099ff" height="23" width="151">
          <p align="center">
          <input type="submit" value="Valider" name="ok"></p>    </td>
        <td bgcolor="#0099ff" width="204"><p align="center"> </td>
        <td bgcolor="#0099ff" width="220" colspan="5">
          <div align="center">
            <input type="reset" value="Annuler" name="reset">
          </div></td>
      </tr></table>
    </br></br>
        <a href="saisie_clt.html();"><font color="#0066FF">Retour</font></a>
    </form>
    </div>
    </body>
     
    </html>
    code php :ouverture.php
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    <?php
    $c=mysql_connect("localhost","root","");
    mysql_select_db("gestion hebergement",$c);
     $nom_clt=$_POST['nom_clt'];
        $com_clt=$_POST['com_clt'];
        $adr_clt=$_POST['adr_clt'];
        $tel_clt =$_POST['tel_clt'];
        $ville_clt=$_POST['ville_clt'];
        $email_clt= $_POST['email_clt'];
    ?>
    Code php : ecriture_clt.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
     
    <?
    $etat=0;
     
    if ($nom_clt =='')
    {
    echo '<font size="4" face="Verdana, Arial, Helvetica, sans-serif">
                      <div align="center"><font color="#FD0000"> 
    <p align=center>saisie le nom Client</p>';
    $etat=1;
    }
     
    if ($email_clt =='')
    {
    echo '<font size="4" face="Verdana, Arial, Helvetica, sans-serif">
                      <div align="center"><font color="#FD0000"> 
    <p align=center>saisie L'e-mail</p>';
    $etat=1;
    }
    
    if ($etat==0)
    {
    
    include"ouverture.php";
    
    $query[] = "INSERT INTO `client` VALUES ('', '$nom_clt', '$com_clt','$adr_clt', 'ville', '$tel_clt', 'email_clt' );";
    while ($each_query = each($query))
    {
     $result = mysql_query($each_query[1]);
     if (!$result)
     {echo("<b>Il y a un erreur a la BDD. L erreur c est '.mysql_error()).'<p><a href="saisie_clt.html">Retour</a></p>";
    
     }
    }
    echo '<p font size="4" face="Verdana, Arial, Helvetica, sans-serif">
                      <div align="center"><font color="#003399"><br>Le Client '.'$nom_clt'.' est inserer avec success <img src="../images/button_cancel.png" width="18" height="24"> </p></div>';
    require(saisie_clt.html');
    }
    ?>
    quand je saisie tous les champs il la page m'apparait ceci (cliquer sur l'image)
    Merci de me repondre parceque je me suis beugué sur Ca depuis des semaines

  2. #2
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Par défaut
    Il faut echapper l'apostrophe dans ta chaine :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    echo '<font size="4" face="Verdana, Arial, Helvetica, sans-serif">
                      <div align="center"><font color="#FD0000"> 
    <p align=center>saisie L\'e-mail</p>';
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

Discussions similaires

  1. Réponses: 4
    Dernier message: 25/06/2013, 13h25
  2. supprimer un enregistrement si un champ est vide
    Par kuhnden dans le forum Access
    Réponses: 2
    Dernier message: 15/02/2006, 19h39
  3. Tester si champs est vide
    Par clems34 dans le forum PostgreSQL
    Réponses: 3
    Dernier message: 19/09/2005, 20h53
  4. Utiliser IF quand le champ est vide... (critère)
    Par samlepiratepaddy dans le forum Access
    Réponses: 5
    Dernier message: 19/09/2005, 15h57
  5. [Access] Comment savoir qu'un champs est vide ?
    Par Oberown dans le forum ASP
    Réponses: 9
    Dernier message: 25/10/2004, 10h47

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