Select

ViPHP
ViPHP | 2291 Messages

09 août 2006, 14:26

Bonjour,

Dans un formulaire j'ai un select qui va chercher les données dans une TABLE
$select = 'SELECT etat  FROM etat_installation';
$result = mysql_query($select) or die ('Erreur : '.mysql_error() );
$total = mysql_num_rows($result);


$result = mysql_query($select);
echo "<select name='etat_installation'>";
while($row = mysql_fetch_array($result))
{
        echo "<option value='".$row['code'] ."'>".$row['etat'];" </option>\n";

}
echo '</select>'."\n";
Mais je voudrais que le premier choix soit en rouge, et surtout qu'il ne puisse pas être selectionner (enfin que si l'utilisateur de fait pas un choix et laisse sur la valeut par défaut qu'un message apparaise en lui demandant de faire un choix) c'est facile à faire avec js mais je ne sais vraiment pas comment le faire quand ont va chercher les infos dans une table
Ma TABLE
CREATE TABLE `etat_installation` (
  `id_etat` tinyint(4) NOT NULL auto_increment,
  `etat` varchar(50) character set latin1 collate latin1_german1_ci NOT NULL,
  `code` varchar(50) character set latin1 collate latin1_german1_ci NOT NULL,
  PRIMARY KEY  (`id_etat`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

D'avance merci
ImageCe que l'on apprend par l'effort reste toujours ancré beaucoup plus longtemps.

Mammouth du PHP | 601 Messages

09 août 2006, 14:35

sert toi d'une règle css pour l'affichage
donc :

Code : Tout sélectionner

#rouge { color:red; } echo "<option id=\"rouge\" value='".$row['code'] ."'>".$row['etat'];" </option>\n";
http://xavier-artot.com
¨'°-.,¸¸,.-·²°'´¨'°-.,¸¸,.-·²°'´¨'°-.,¸¸,.-·°'´¨
système d'exploitation "Ubuntu 7.10"

Eléphant du PHP | 353 Messages

09 août 2006, 14:38

Pour ce qui est des couleurs, c'est simple tu mets un <option> comme ceci =>
<option value="" style=" color:#FF0000">Default</option>
Maintenant , pour forcer à choisir , tu dois vérifier par javascript ou alors après le submit de ta variable.

javascript:
// dans ta balise form
onSubmit="check_etat()" ;

<script>
function check_etat()
           {
//Pas oublier de mettre id="etat_installation" pour ton select
           var value_etat = getElementById['etat_installation'].value;
           if(value_etat != "")
                {
                 return true;
                }
           else{
                  return false ;
                  }
           }
</script>
php:
if($_POST['etat_installation'] == "")
      {
        echo "Vous devez choisir l'etat d'installation";
      }
else{
       // Continuer ta requete
      }

ViPHP
ViPHP | 2291 Messages

09 août 2006, 15:37

Pour ce qui est des couleurs, c'est simple tu mets un <option> comme ceci =>
<option value="" style=" color:#FF0000">Default</option>
Maintenant , pour forcer à choisir , tu dois vérifier par javascript ou alors après le submit de ta variable.

javascript:
// dans ta balise form
onSubmit="check_etat()" ;

<script>
function check_etat()
           {
//Pas oublier de mettre id="etat_installation" pour ton select
           var value_etat = getElementById['etat_installation'].value;
           if(value_etat != "")
                {
                 return true;
                }
           else{
                  return false ;
                  }
           }
</script>
php:
if($_POST['etat_installation'] == "")
      {
        echo "Vous devez choisir l'etat d'installation";
      }
else{
       // Continuer ta requete
      }
Merci mais je plante cela ne fonctionne pas, j'ai le control qui ne se fait pas
Voici fichier include (le select)
$select = 'SELECT etat  FROM etat_installation';
$result = mysql_query($select) or die ('Erreur : '.mysql_error() );
$total = mysql_num_rows($result);


$result = mysql_query($select);
echo "<select name='etat_installation'>";
while($row = mysql_fetch_array($result))
{
        echo "<option value='".$row['code'] ."'>".$row['etat'];" </option>\n";



}
echo '</select>'."\n";
Il aurais t'il une erreur ?
ImageCe que l'on apprend par l'effort reste toujours ancré beaucoup plus longtemps.

Eléphant du PHP | 353 Messages

09 août 2006, 15:51

puis je vois ton code complet ?

ViPHP
ViPHP | 2291 Messages

09 août 2006, 15:56

puis je vois ton code complet ?
Ok voici le form
<form method="POST"  name="prestations_tvc" action="../enregistrement/validation_tvc.php">
        <table border="0" id="table5" width="931">
                <tr>
                        <td width="453"><font size="2">Date de l'installation :</font><input type="text" name="T21" size="20">
                        </td>
                        <td>
                        <p align="right"><font size="2">Date du jour </font>:
                        <input type="text" name="T22" size="20"></p>
                        </td>
                </tr>
        </table>
        <table border="0" id="table3" width="935" bgcolor="#C0C0C0" style="background-image: url('../../img/bg.gif')">
                <tr>
                        <td width="69" align="center"><b><font size="1">Ref client</font></b></td>
                        <td width="248" align="center"><b><font size="1">Adresse client</font></b></td>
                        <td width="66" align="center"><font size="2">nom</font></td>
                        <td width="65" align="center"><b><font size="1">code postal</font></b></td>
                        <td width="71" align="center"><b><font size="1">Localité</font></b></td>
                        <td align="center"><b><font size="1">Adresse MAC</font></b></td>
                </tr>
                <tr>
                        <td width="69" align="center">
                        <input type="text" name="ref[1]" size="7"></td>
                        <td width="248" align="center">
                        <input type="text" name="adr[1]" size="36"></td>
                        <td width="66" align="center">
                        <p align="center">
                        <input type="text" name="ref[1]0" size="12"></p>
                        </td>
                        <td width="65" align="center">
                        <input type="text" name="postal[1]" size="6"></td>
                        <td width="71" align="center">
                        <p align="center"><input type="text" name="loca[1]" size="12"></p>
                        </td>
                        <td align="center" style="position: relative; float: left">
                                                <p align="left"><input type="text" name="mac[1]" size="2">:<input type="text" name="mac[2]" size="2">:<input type="text" name="mac[3]" size="2">:<input type="text" name="mac[4]" size="2">:<input type="text" name="mac[5]" size="2">:<input type="text" name="mac[6]" size="2"></td>
                </tr>
        </table>
        <table id="table4" width="935" bgcolor="#C0C0C0" style="border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; background-image: url('../../img/bg.gif')">
                <tr>
                        <td width="92" align="center"><b><font size="1">Technicien</font></b></td>
                        <td width="97" align="center"><b><font size="1">Arrivé</font></b></td>
                        <td width="104" align="center"><b><font size="1">Départ</font></b></td>
                        <td width="83" align="center"><b><font size="1">Téléphone client</font></b></td>
                        <td width="256" align="center"><b><font size="1">Etat de
                        l'installation</font></b></td>
                        <td align="center"><b><font size="1">Commentaire</font></b></td>
                </tr>
                <tr>
                        <td width="92" align="center" style="border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-style: solid; border-bottom-width: 1px">
                        <?php include ('select_technicien.php'); ?>
                        <td align="center" style="border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-style: solid; border-bottom-width: 1px">
                        <input type="text" name="ha[1]" size="2" maxlength="2">H<input type="text" name="ha[2]" size="2" maxlength="2"></td>
                        <td align="center" style="border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-style: solid; border-bottom-width: 1px">
                        <input type="text" name="hd[1]" size="2" maxlength="2">H<input type="text" name="hd[2]" size="2" maxlength="2"></td>
                        <td width="83" align="center" style="border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-style: solid; border-bottom-width: 1px">
                        <input type="text" name="tel[1]" size="10"></td>
                        <td width="256" align="center" style="border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-style: solid; border-bottom-width: 1px">
                        <!--webbot bot="HTMLMarkup" startspan --><?php include ('select_etat_install.php'); ?><!--webbot bot="HTMLMarkup" endspan i-checksum="46300" --></td>
                        <td align="center" style="border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-style: solid; border-bottom-width: 1px">
                        <textarea rows="3" name="com[1]" cols="30"></textarea></td>
                </tr>
        </table>
        <table border="0" id="table6" width="935" style="background-image: url('../../img/tile_bg.gif')">
                <tr>
                        <td width="69" align="center"><b><font size="1" color="#FFFFFF">Ref
                        client</font></b></td>
                        <td width="248" align="center"><b><font size="1" color="#FFFFFF">
                        Adresse client</font></b></td>
                        <td width="131" align="center"><b><font size="1" color="#FFFFFF">
                        code postal</font></b></td>
                        <td width="125" align="center"><b><font size="1" color="#FFFFFF">
                        Localité</font></b></td>
                        <td align="center"><b><font size="1" color="#FFFFFF">Adresse MAC</font></b></td>
                </tr>
                <tr>
                        <td width="69" align="center"><font color="#FFFFFF">
                        <input type="text" name="T23" size="12"></font></td>
                        <td width="248" align="center">
                        <input type="text" name="adr[1]0" size="36"></td>
                        <td width="131" align="center">
                        <p align="center"><font color="#FFFFFF">
                        <input type="text" name="T25" size="12"></font></p>
                        </td>
                        <td width="125" align="center">
                        <p align="center"><font color="#FFFFFF">
                        <input type="text" name="T26" size="12"></font></p>
                        </td>
                        <td align="center">
                                                <p align="center">
                                                <input type="text" name="mac[1]0" size="2">:<input type="text" name="mac[2]0" size="2">:<input type="text" name="mac[3]0" size="2">:<input type="text" name="mac[4]0" size="2">:<input type="text" name="mac[5]0" size="2">:<input type="text" name="mac[6]0" size="2"></td>
                </tr>
        </table>
        <table border="0" id="table7" width="935" style="background-image: url('../../img/tile_bg.gif')">
                <tr>
                        <td width="118" align="center"><b><font size="1" color="#FFFFFF">
                        Technicien</font></b></td>
                        <td width="92" align="center"><b><font size="1" color="#FFFFFF">
                        Arrivé</font></b></td>
                        <td width="83" align="center"><b><font size="1" color="#FFFFFF">
                        Départ</font></b></td>
                        <td width="83" align="center"><b><font size="1" color="#FFFFFF">
                        Téléphone client</font></b></td>
                        <td width="256" align="center"><b><font size="1" color="#FFFFFF">
                        Etat de l'installation</font></b></td>
                        <td align="center"><b><font size="1" color="#FFFFFF">Commentaire</font></b></td>
                </tr>
                <tr>
                        <td width="118" align="center"><?php include ('select_technicien.php'); ?></td>
                        <td align="center"><font color="#FFFFFF">
                        <input type="text" name="T33" size="2" maxlength="2">H<input type="text" name="T34" size="2" maxlength="2"></font></td>
                        <td align="center"><font color="#FFFFFF">
                        <input type="text" name="T35" size="2" maxlength="2">H<input type="text" name="T36" size="2" maxlength="2"></font></td>
                        <td width="83" align="center"><font color="#FFFFFF">
                        <input type="text" name="T37" size="10"></font></td>
                        <td width="256" align="center">
                                                <!--webbot bot="HTMLMarkup" startspan --><?php include ('select_etat_install.php'); ?><!--webbot bot="HTMLMarkup" endspan i-checksum="46300" --></td>
                        <td align="center"><font color="#FFFFFF">
                        <textarea rows="3" name="S2" cols="30"></textarea></font></td>
                </tr>
        </table>
        <table border="0" id="table8" width="935" bgcolor="#C0C0C0" style="background-image: url('../../img/bg.gif')">
                <tr>
                        <td width="69" align="center"><b><font size="1">Ref client</font></b></td>
                        <td width="248" align="center"><b><font size="1">Adresse client</font></b></td>
                        <td width="131" align="center"><b><font size="1">code postal</font></b></td>
                        <td width="125" align="center"><b><font size="1">Localité</font></b></td>
                        <td align="center"><b><font size="1">Adresse MAC</font></b></td>
                </tr>
                <tr>
                        <td width="69" align="center">
                        <input type="text" name="T38" size="12"></td>
                        <td width="248" align="center">
                        <input type="text" name="adr[1]1" size="36"></td>
                        <td width="131" align="center">
                        <p align="center"><input type="text" name="T40" size="12"></p>
                        </td>
                        <td width="125" align="center">
                        <p align="center"><input type="text" name="T41" size="12"></p>
                        </td>
                        <td align="center">
                                                <p align="center">
                                                <input type="text" name="mac[1]2" size="2">:<input type="text" name="mac[2]2" size="2">:<input type="text" name="mac[3]2" size="2">:<input type="text" name="mac[4]2" size="2">:<input type="text" name="mac[5]2" size="2">:<input type="text" name="mac[6]2" size="2"></td>
                </tr>
        </table>
        <table border="0" id="table9" width="935" bgcolor="#C0C0C0" style="background-image: url('../../img/bg.gif')">
                <tr>
                        <td width="92" align="center"><b><font size="1">Technicien</font></b></td>
                        <td width="97" align="center"><b><font size="1">Arrivé</font></b></td>
                        <td width="104" align="center"><b><font size="1">Départ</font></b></td>
                        <td width="83" align="center"><b><font size="1">Téléphone client</font></b></td>
                        <td width="256" align="center"><b><font size="1">Etat de
                        l'installation</font></b></td>
                        <td align="center"><b><font size="1">Commentaire</font></b></td>
                </tr>
                <tr>
                        <td width="92" align="center">
                                                <!--webbot bot="HTMLMarkup" startspan --><?php include ('select_technicien.php'); ?><!--webbot bot="HTMLMarkup" endspan i-checksum="40297" --></td>
                        <td align="center">
                        <input type="text" name="T48" size="2" maxlength="2">H<input type="text" name="T49" size="2" maxlength="2"></td>
                        <td align="center">
                        <input type="text" name="T50" size="2" maxlength="2">H<input type="text" name="T51" size="2" maxlength="2"></td>
                        <td width="83" align="center">
                        <input type="text" name="T52" size="10"></td>
                        <td width="256" align="center">
                                                <!--webbot bot="HTMLMarkup" startspan --><?php include ('select_etat_install.php'); ?><!--webbot bot="HTMLMarkup" endspan i-checksum="46300" --></td>
                        <td align="center"><textarea rows="3" name="S3" cols="30"></textarea></td>
                </tr>
        </table>
        <table border="0" id="table10" width="935" style="background-image: url('../../img/tile_bg.gif')">
                <tr>
                        <td width="69" align="center"><b><font size="1" color="#FFFFFF">Ref
                        client</font></b></td>
                        <td width="248" align="center"><b><font size="1" color="#FFFFFF">
                        Adresse client</font></b></td>
                        <td width="131" align="center"><b><font size="1" color="#FFFFFF">
                        code postal</font></b></td>
                        <td width="125" align="center"><b><font size="1" color="#FFFFFF">
                        Localité</font></b></td>
                        <td align="center"><b><font size="1" color="#FFFFFF">Adresse MAC</font></b></td>
                </tr>
                <tr>
                        <td width="69" align="center"><font color="#FFFFFF">
                        <input type="text" name="T53" size="12"></font></td>
                        <td width="248" align="center">
                        <input type="text" name="adr[1]2" size="36"></td>
                        <td width="131" align="center">
                        <p align="center"><font color="#FFFFFF">
                        <input type="text" name="T55" size="12"></font></p>
                        </td>
                        <td width="125" align="center">
                        <p align="center"><font color="#FFFFFF">
                        <input type="text" name="T56" size="12"></font></p>
                        </td>
                        <td align="center">
                                                <p align="center">
                                                <input type="text" name="mac[1]3" size="2">:<input type="text" name="mac[2]3" size="2">:<input type="text" name="mac[3]3" size="2">:<input type="text" name="mac[4]3" size="2">:<input type="text" name="mac[5]3" size="2">:<input type="text" name="mac[6]3" size="2"></td>
                </tr>
        </table>
        <table border="0" id="table11" width="935" style="background-image: url('../../img/tile_bg.gif')">
                <tr>
                        <td width="92" align="center"><b><font size="1" color="#FFFFFF">
                        Technicien</font></b></td>
                        <td width="97" align="center"><b><font size="1" color="#FFFFFF">
                        Arrivé</font></b></td>
                        <td width="104" align="center"><b><font size="1" color="#FFFFFF">
                        Départ</font></b></td>
                        <td width="83" align="center"><b><font size="1" color="#FFFFFF">
                        Téléphone client</font></b></td>
                        <td width="256" align="center"><b><font size="1" color="#FFFFFF">
                        Etat de l'installation</font></b></td>
                        <td align="center"><b><font size="1" color="#FFFFFF">Commentaire</font></b></td>
                </tr>
                <tr>
                        <td width="92" align="center">
                                                <!--webbot bot="HTMLMarkup" startspan --><?php include ('select_technicien.php'); ?><!--webbot bot="HTMLMarkup" endspan i-checksum="40297" --></td>
                        <td align="center"><font color="#FFFFFF">
                        <input type="text" name="T63" size="2" maxlength="2">H<input type="text" name="T64" size="2" maxlength="2"></font></td>
                        <td align="center"><font color="#FFFFFF">
                        <input type="text" name="T65" size="2" maxlength="2">H<input type="text" name="T66" size="2" maxlength="2"></font></td>
                        <td width="83" align="center"><font color="#FFFFFF">
                        <input type="text" name="T67" size="10"></font></td>
                        <td width="256" align="center">
                                                <!--webbot bot="HTMLMarkup" startspan --><?php include ('select_etat_install.php'); ?><!--webbot bot="HTMLMarkup" endspan i-checksum="46300" --></td>
                        <td align="center"><font color="#FFFFFF">
                        <textarea rows="3" name="S4" cols="30"></textarea></font></td>
                </tr>
        </table>
        <table border="0" id="table12" width="935" bgcolor="#C0C0C0" style="background-image: url('../../img/bg.gif')">
                <tr>
                        <td width="69" align="center"><b><font size="1">Ref client</font></b></td>
                        <td width="248" align="center"><b><font size="1">Adresse client</font></b></td>
                        <td width="131" align="center"><b><font size="1">code postal</font></b></td>
                        <td width="125" align="center"><b><font size="1">Localité</font></b></td>
                        <td align="center"><b><font size="1">Adresse MAC</font></b></td>
                </tr>
                <tr>
                        <td width="69" align="center">
                        <input type="text" name="T68" size="12"></td>
                        <td width="248" align="center">
                        <input type="text" name="adr[1]3" size="36"></td>
                        <td width="131" align="center">
                        <p align="center"><input type="text" name="T70" size="12"></p>
                        </td>
                        <td width="125" align="center">
                        <p align="center"><input type="text" name="T71" size="12"></p>
                        </td>
                        <td align="center">
                                                <p align="center">
                                                <input type="text" name="mac[1]4" size="2">:<input type="text" name="mac[2]4" size="2">:<input type="text" name="mac[3]4" size="2">:<input type="text" name="mac[4]4" size="2">:<input type="text" name="mac[5]4" size="2">:<input type="text" name="mac[6]4" size="2"></td>
                </tr>
        </table>
        <table border="0" id="table13" width="935" bgcolor="#C0C0C0" style="background-image: url('../../img/bg.gif')">
                <tr>
                        <td width="92" align="center"><b><font size="1">Technicien</font></b></td>
                        <td width="97" align="center"><b><font size="1">Arrivé</font></b></td>
                        <td width="104" align="center"><b><font size="1">Départ</font></b></td>
                        <td width="83" align="center"><b><font size="1">Téléphone client</font></b></td>
                        <td width="256" align="center"><b><font size="1">Etat de
                        l'installation</font></b></td>
                        <td align="center"><b><font size="1">Commentaire</font></b></td>
                </tr>
                <tr>
                        <td width="92" align="center">
                                                <!--webbot bot="HTMLMarkup" startspan --><?php include ('select_technicien.php'); ?><!--webbot bot="HTMLMarkup" endspan i-checksum="40297" --></td>
                        <td align="center">
                        <input type="text" name="T78" size="2" maxlength="2">H<input type="text" name="T79" size="2" maxlength="2"></td>
                        <td align="center">
                        <input type="text" name="T80" size="2" maxlength="2">H<input type="text" name="T81" size="2" maxlength="2"></td>
                        <td width="83" align="center">
                        <input type="text" name="T82" size="10"></td>
                        <td width="256" align="center">
                                                <!--webbot bot="HTMLMarkup" startspan --><?php include ('select_etat_install.php'); ?><!--webbot bot="HTMLMarkup" endspan i-checksum="46300" --></td>
                        <td align="center"><textarea rows="3" name="S5" cols="30"></textarea></td>
                </tr>
        </table>
        <table border="0" id="table14" width="935" style="background-image: url('../../img/tile_bg.gif')">
                <tr>
                        <td width="69" align="center"><b><font size="1" color="#FFFFFF">Ref
                        client</font></b></td>
                        <td width="248" align="center"><b><font size="1" color="#FFFFFF">
                        Adresse client</font></b></td>
                        <td width="131" align="center"><b><font size="1" color="#FFFFFF">
                        code postal</font></b></td>
                        <td width="125" align="center"><b><font size="1" color="#FFFFFF">
                        Localité</font></b></td>
                        <td align="center"><b><font size="1" color="#FFFFFF">Adresse MAC</font></b></td>
                </tr>
                <tr>
                        <td width="69" align="center"><font color="#FFFFFF">
                        <input type="text" name="T83" size="12"></font></td>
                        <td width="248" align="center">
                        <input type="text" name="adr[1]4" size="36"></td>
                        <td width="131" align="center">
                        <p align="center"><font color="#FFFFFF">
                        <input type="text" name="T85" size="12"></font></p>
                        </td>
                        <td width="125" align="center">
                        <p align="center"><font color="#FFFFFF">
                        <input type="text" name="T86" size="12"></font></p>
                        </td>
                        <td align="center">
                                                <p align="center">
                                                <input type="text" name="mac[1]5" size="2">:<input type="text" name="mac[2]5" size="2">:<input type="text" name="mac[3]5" size="2">:<input type="text" name="mac[4]5" size="2">:<input type="text" name="mac[5]5" size="2">:<input type="text" name="mac[6]5" size="2"></td>
                </tr>
        </table>
        <table border="0" id="table15" width="935" style="background-image: url('../../img/tile_bg.gif')">
                <tr>
                        <td width="92" align="center"><b><font size="1" color="#FFFFFF">
                        Technicien</font></b></td>
                        <td width="97" align="center"><b><font size="1" color="#FFFFFF">
                        Arrivé</font></b></td>
                        <td width="104" align="center"><b><font size="1" color="#FFFFFF">
                        Départ</font></b></td>
                        <td width="83" align="center"><b><font size="1" color="#FFFFFF">
                        Téléphone client</font></b></td>
                        <td width="256" align="center"><b><font size="1" color="#FFFFFF">
                        Etat de l'installation</font></b></td>
                        <td align="center"><b><font size="1" color="#FFFFFF">Commentaire</font></b></td>
                </tr>
                <tr>
                        <td width="92" align="center">
                                                <!--webbot bot="HTMLMarkup" startspan --><?php include ('select_technicien.php'); ?><!--webbot bot="HTMLMarkup" endspan i-checksum="40297" --></td>
                        <td align="center"><font color="#FFFFFF">
                        <input type="text" name="T93" size="2" maxlength="2">H<input type="text" name="T94" size="2" maxlength="2"></font></td>
                        <td align="center"><font color="#FFFFFF">
                        <input type="text" name="T95" size="2" maxlength="2">H<input type="text" name="T96" size="2" maxlength="2"></font></td>
                        <td width="83" align="center"><font color="#FFFFFF">
                        <input type="text" name="T97" size="10"></font></td>
                        <td width="256" align="center">
                                                <!--webbot bot="HTMLMarkup" startspan --><?php include ('select_etat_install.php'); ?><!--webbot bot="HTMLMarkup" endspan i-checksum="46300" --></td>
                        <td align="center"><font color="#FFFFFF">
                        <textarea rows="3" name="S6" cols="30"></textarea></font></td>
                </tr>
        </table>
        <p align="center"><input type="submit" value="Envoyer" name="B1"><input type="reset" value="Rétablir" name="B2"></p>
</form>
Le fichier validation (enfin le debut) il est pas fini
<?php
include "../../connect/fc-phpconnect.php";

if($_POST['etat_installation'] == "")
      {
        echo "Vous devez choisir l'etat d'installation";
      }
else{
       // suite des requettes
      }
/********************************************************************************
Récupération des données.
/*******************************************************************************/
$date = $_POST["date_realisation"];
$date2 = $_POST["date_encodage"];
$user = $_POST["user"];
$ref = $_POST["ref"];
$adr = $_POST["adr"];
$code = $_POST["postal"];
$localite = $_POST["loca"];
$address_mac = $_POST['mac_1'].":".$_POST['mac_2'].":".$_POST['mac_3'].":".$_POST['mac_4'].":".$_POST['mac_5'].":".$_POST['mac_6'] ;
$tech = $_POST["technicien"];
$heure_debut = $_POST['ha1'].":".$_POST['ha2'];
$heure_fin = $_POST['hd1'].":".$_POST['hd2'];
$commentaire = $_POST['com'];








/********************************************************************************
Insertion dans la base
********************************************************************************/


                                        $sql = "INSERT INTO chantier VALUES ";
                                        $sql.= "('', '$date', '$date2', '$user', '$ref', '$adr', '$code', '$localite', '$address_mac', '$tech', '$heure_debut', 'heure_fin', 'commentaire')";

                                        $insert = mysql_query($sql) or die (mysql_error());
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<body background="../../img/grd-4px.gif">
<?php
echo "Merci les informations sont enregistr&eacutees.";
?>
<a href="../deconnexion.php"><font color="#FF0000">D&eacuteconnexion</font></a>

</body>
</html>
Et le fichier qui contient le select
<?php

include "../../connect/fc-phpconnect.php";


$select = 'SELECT etat  FROM etat_installation';
$result = mysql_query($select) or die ('Erreur : '.mysql_error() );
$total = mysql_num_rows($result);


$result = mysql_query($select);
echo "<select name='etat_installation'>";
while($row = mysql_fetch_array($result))
{
        echo "<option value='".$row['code'] ."'>".$row['etat'];" </option>\n";



}
echo '</select>'."\n";
?>
Voilà :oops:
ImageCe que l'on apprend par l'effort reste toujours ancré beaucoup plus longtemps.

Eléphant du PHP | 353 Messages

09 août 2006, 17:54

si tu fais, un print $_POST['etat_installation'] dans la page où tu enregistre dans la database , ca donne quoi ?

Avatar du membre
ViPHP
ViPHP | 3008 Messages

10 août 2006, 18:54

Une erreur glissée ici :
echo "<option value='".$row['code'] ."'>".$row['etat'];" </option>\n";
qui devrait être
echo "<option value='".$row['code']."'>".$row['etat']."</option>\n"; 

ViPHP
ViPHP | 2291 Messages

10 août 2006, 22:34

Une erreur glissée ici :
echo "<option value='".$row['code'] ."'>".$row['etat'];" </option>\n";
qui devrait être
echo "<option value='".$row['code']."'>".$row['etat']."</option>\n"; 
Bon alors finalement je récupére presque tout je récupére comme ceci
.$_POST['ref'][1].
Par contre je n'arrive pas récupérer le nom d'utilisateur de la session
Dans mon form j'ai ceci qui fonctionne correctement
<?php echo "Bonjour, ".$_SESSION['nom'];?> 
Et dans mon fichier validation j'essaye de le récupérer comme ceci
$user = $_SESSION['nom'];  
ET je fais un insert comme ceci
.$_SESSION['nom'].
Et evidament comme souvent cela ne fonctionne pas j'ai un champ vide dans ma TABLE

QUelqu'un à t'il une solution ? :lol:

D'avance merci
ImageCe que l'on apprend par l'effort reste toujours ancré beaucoup plus longtemps.

ViPHP
ViPHP | 2291 Messages

10 août 2006, 22:47

Ok merci j'ai trouvé
Voici mon fichier finie et qui fonctionne :lol:
<?php
session_start();
if (!isset($_SESSION['login'])) {
header ('Location: ../index.php');
    exit();
}
/******************************************************************************************************************************************************
                          Connexion à la base
******************************************************************************************************************************************************/

include "../../connect/fc-phpconnect.php";

/*****************************************************************************************************************************************************
                                                                     Récupération des données de la première ligne.
*****************************************************************************************************************************************************/
$date1 = $_POST['date_realisation'][1];
$date2 = $_POST['date_encodage'][2];
$user = $_SESSION['nom'];
$ref = $_POST['ref'][1];
$nom = $_POST['nom'][1];
$adr = $_POST['adr'][1];
$code = $_POST['postal'][1];
$commune = $_POST['commune'][1];
$address_mac = $_POST['mac'][1].":".$_POST['mac'][2].":".$_POST['mac'][3].":".$_POST['mac'][4].":".$_POST['mac'][5].":".$_POST['mac'][6] ;
$tech = $_POST['technicien'];
$heure_debut = $_POST['ha'][1].":".$_POST['ha'][2];
$heure_fin = $_POST['hd'][1].":".$_POST['hd'][1];
$installation = $_POST['installation'];
$commentaire = $_POST['com'][1];

/*****************************************************************************************************************************************************
                                                                  Insertion dans la base  de la ligne 2.
*****************************************************************************************************************************************************/

                                           $sql = "INSERT INTO prestation_beta (date_realisation, date_encodage, nom_utilisateur, ref_client, nom_client, adr_client, code_postal, commune, adr_modem, technicien, heure_debut, heure_fin, etat_installation, commentaire) values ( '".$date1."','".$date2."','".$user."','".$ref."','".$nom."','".$adr."','".$code."','".$commune."','".$address_mac."', '".$tech."','".$heure_debut."','".$heure_fin."','".$installation."','".$commentaire."')";


                                             $insert = mysql_query($sql) or die (mysql_error());


?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<body background="../../img/grd-4px.gif">
<?php
echo "Merci les informations sont enregistr&eacutees.";
?>
<a href="../deconnexion.php"><font color="#FF0000">D&eacuteconnexion</font></a>

</body>
</html>
Je suis ouvert à toutes remarques :wink:
Et j'aurais encore une question ceci concerne une seule ligne de mon form mais j'ai besoin de 5 lignes en plus alors je comptais faire ceci 5x
$date1 = $_POST['date_realisation'][3];
$date2[2] = $_POST['date_encodage'][4];
$user = $_SESSION['nom'];
$ref[2] = $_POST['ref'][2];
$nom[2] = $_POST['nom'][2];
$adr[2] = $_POST['adr'][2];
$code[2] = $_POST['postal'][2];
$commune[2] = $_POST['commune'][2];
$address_mac[2] = $_POST['mac'][7].":".$_POST['mac'][8].":".$_POST['mac'][9].":".$_POST['mac'][10].":".$_POST['mac'][11].":".$_POST['mac'][12] ;
$tech = $_POST['technicien'];
$heure_debut[2] = $_POST['ha'][3].":".$_POST['ha'][4];
$heure_fin[2] = $_POST['hd'][5].":".$_POST['hd'][6];
$installation = $_POST['installation'];
$commentaire[2] = $_POST['com'][2];

/*****************************************************************************************************************************************************
                                                                  Insertion dans la base  de la ligne 2.
*****************************************************************************************************************************************************/

                                           $sql = "INSERT INTO prestation_beta (date_realisation, date_encodage, nom_utilisateur, ref_client, nom_client, adr_client, code_postal, commune, adr_modem, technicien, heure_debut, heure_fin, etat_installation, commentaire) values ( '".$date1."','".$date2."','".$user."','".$ref[2]."','".$nom[2]."','".$adr[2]."','".$code[2]."','".$commune[2]."','".$address_mac[2]."', '".$tech."','".$heure_debut."','".$heure_fin."','".$installation."','".$commentaire[2]."')";


                                             $insert = mysql_query($sql) or die (mysql_error());


?>
Et ainsi de suite pour les 4 autres mais je ne suis pas certain que cela est la meilleurs solution....
ImageCe que l'on apprend par l'effort reste toujours ancré beaucoup plus longtemps.

Eléphant du PHP | 101 Messages

10 août 2006, 23:09

tu ne prêtes pas attention aux injections SQL potentielles ? : /

ViPHP
ViPHP | 2291 Messages

10 août 2006, 23:11

:afraid: QUOI :?: :?:
ImageCe que l'on apprend par l'effort reste toujours ancré beaucoup plus longtemps.

Eléphant du PHP | 101 Messages

10 août 2006, 23:17

au temps pour moi.. je croyais qu'il s'agissait d'un formulaire d'inscription pas d'administration.. : s

ViPHP
ViPHP | 2291 Messages

10 août 2006, 23:26

:wink:
ImageCe que l'on apprend par l'effort reste toujours ancré beaucoup plus longtemps.