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 126 127 128 129 130 131 132 133
| <?php
$server="localhost";
$bdd="*****";
$user="user";
$mdps="*****";
$connection=mysql_connect ($server,$user,$mdps)
or die (mysql_connect_error());
$select_db=mysql_select_db($bdd,$connection);
$query_test="SELECT poste_tbl.poste_nom, section_tbl.section_nom, section_tbl.section_desc FROM Poste_tbl, Section_tbl WHERE section_tbl.section_id=Poste_tbl.section_id";
$result=mysql_query($query_test) or die ('Erreur SQL a la ligne :<br>'.$sql.'<br>'.__LINE__);
if ($resultat){
while ($resultat=mysql_fetch_array($result))
{
echo '<p>poste_nom :' .$resultat['poste_nom'].'<br>';
echo 'id section :' .$resultat['section_id'].'<br>';
echo 'nom section :' .$resultat['section_nom']. '<br>';
echo 'desc section :' .$resultat['section_desc'].'<br></p>';
}
}
else
{
echo 'il ny a aucun enregistrement';
}
//-----------------------------------------------------------------------------------------------------------------
// AJOUTER UN POSTE
//-----------------------------------------------------------------------------------------------------------------
?>
<BODY>
<form action="essai_poste_section.php" method="post">
<!-- <br> -->
<table border=0>
<tr>
<td align="left">AJOUTER POSTE</td>
</tr>
<tr>
<td align="left">NOM</td><td align="left">DESCRIPTION</td><td align="left">SECTION</td>
</tr>
<tr>
<td><input type="text" name="nom" value="" maxlenght=20></td><td><input type="text" name="desc" value="" maxlenght=45 onfocus,value=""></td>
<td>
<?php
//-----------------------------------------------------------------------------------------------------------------
// CHOIX SECTION (liste déroulante)
//-----------------------------------------------------------------------------------------------------------------
// Configuration de la connexion à la base de données
$server="localhost";
$bdd="*****";
$user="user";
$mdps="*****";
$choix = isset($_POST['choix']) ? $_POST['choix'] : '';
// ...
// Connexion à la base de donnée
mysql_pconnect($server, $user, $mdps) or die('<h1>Connexion au serveur impossible !</h1>');
mysql_select_db( $bdd) or die('<h1>Connexion impossible à la base</h1>');
// Affichage du langage choisi
if ($choix) {
$query = mysql_query("SELECT section_nom FROM section_tbl WHERE section_nom='$choix';") or die (mysql_error());
$array = mysql_fetch_array($query);
// echo 'Vous avez choisi la section : ' . $array['section_nom'];
}
// Début du script
$query = mysql_query("SELECT * FROM section_tbl;") or die (mysql_error());
if ($query) {
echo '<form method="post">';
echo '<select name="choix">';
while ($array = mysql_fetch_array($query))
{
if ($choix == $array["section_nom"])
{
echo '<option value="' . $array['section_nom'] . '" selected>' . $array['section_nom'] . '</option>';
}
else
{
echo '<option value="'.$array['section_nom'] . '">' . $array['section_nom'] . '</option>';
}
}
echo '</select>';
echo '</form>';
}
//mysql_close();
// ...
?>
</td>
</tr>
<tr>
<td align="left"></td>
<td align="left"><input type="submit" name="CREER" value="CREER"></td>
</tr>
</table>
</form>
</body>
<?php
//-----------------------------------------------------------------------------------------------------------------
// TRAITEMENT DONNEE
//-----------------------------------------------------------------------------------------------------------------
//insertion data dans bdd
if ( !empty($post["nom"]) && !empty($post["desc"]))
{
$nom= $_post["nom"];
$desc= $_post["desc"];
}
$sectionnom=$array['section_nom'];
$req_ID="select section_id FROM section_tbl WHERE section_nom=$sectionnom";
$result_sec_id=mysql_query($req_id);
$select_db=mysql_select_db($bdd,$connection);
$ajout="INSERT INTO Poste_tbl('Poste_nom','Poste_desc','section_id')VALUE ('$nom','$desc','$result_sec_id')";
$requete = mysql_query($ajout);
?> |
Partager