<!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=utf-8" />
<title>Untitled Document</title>
<style>
.error {color: #FF0000;}
</style>

</head>

<body>  

<?php
// define variables and set to empty values
$groupeErr=$matiereErr=$classErr = $sectionErr = $cycleErr = "";
$groupe=$class = $section = $cycle = $matiere = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
  if (empty($_POST["classe"])) {
    $ClasseErr = "Classe est Obligatoire";
  } else {
    $classe = test_input($_POST["classe"]);
    // check if name only contains letters and whitespace
    if (!preg_match("/^[a-zA-Z-' ]*$/",$class)) {
      $classe = "Seulement lettre et espace sont permis";
    }
  }
  
  if (empty($_POST["matiere"])) {
    $matiereErr = "Matiere est obligatoire ";
  } else {
    $matiere = test_input($_POST["matiere"]);
    // check if e-mail address is well-formed
  }
    if (empty($_POST["groupe"])) {
    $groupeErr = "Groupe est obligatoire ";
  } else {
    $groupe = test_input($_POST["groupe"]);
    // check if e-mail address is well-formed
  }

   if (empty($_POST["cycle"])) {
    $cycleErr = "Cycle est obligatoire ";
  } else {
    $cycle = test_input($_POST["cycle"]);
    // check if e-mail address is well-formed
            }
  }

function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}
?>

<h2>Collège Notre Dame de la Paix</h2>
<p><span class="error">* Champs Obligatire</span></p>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">  
  Classe: 
  <?php 
  include("_serveur.php");
$sql = 'SELECT * FROM classe  Order By id';
if(!(mysqli_query($link, $sql))){
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
$req=  mysqli_query($link, $sql);
echo 'Matière par classe:';
echo '<label><select name="classe">';
while ($data = mysqli_fetch_array($req)) {
$classe=$data['classe'];
$section=$data['section'];
$classe=strtoupper($classe);
$classid=$data['id'];
 echo' <option value="'.$classeid.'">'.$classe."   ".$section.'</option>';
      
};

echo '</select>';
?>
<br />

  Cycle:  
  <input type="radio" name="cycle" <?php if (isset($cycle) && $cycle=="0") echo "checked";?> value="0">Prescolaire
  <input type="radio" name="cycle" <?php if (isset($cycle) && $cycle=="1") echo "checked";?> value="1">Primaire I
  <input type="radio" name="cycle" <?php if (isset($cycle) && $cycle=="2") echo "checked";?> value="2">Primaire II
   <input type="radio" name="cycle" <?php if (isset($cycle) && $cycle=="3") echo "checked";?> value="3">Complementaire
     <input type="radio" name="cycle" <?php if (isset($cycle) && $cycle=="4") echo "checked";?> value="4">Secondaire
 
  <span class="error">* <?php echo $cycleErr;?></span>
  <br><br>
     Groupe: <input type="text" name="groupe" value="<?php echo $groupe;?>">
  <span class="error">* <?php echo $groupeErr;?></span>
  <br><br>

   Matière: <input type="text" name="matiere" value="<?php echo $matiere;?>">
  <span class="error">* <?php echo $matiereErr;?></span>
  <br><br>
  <input type="submit" name="submit" value="Submit">  
</form>

<?php
echo $classeid.'<br>';
echo $cycle.'<br>';
echo $groupe.'<br>';
echo $matiere.'<br>';

?>
</body>
</html>
