1

I'm using ajax to take user input in a dropdown menu (so the input would be the chosen alternative) and show some information after a button is clicked. It works, but I want to use a switch case statement in the controller, which is not working.

I have this piece of code to populate the dropdown menu:

<form method="post" action="controleur.php">
 <select name="liste_formations" id="liste_formations" class="form-control">
  <option value="">Choisissez une formation</option>
  <?php 
  while($row = mysqli_fetch_array($result))
  {
     echo '<option value="'.$row["idActivite"].'">'.$row["nom"].'</option>';
  }
  ?>
 </select>
</div>
<div class="col-md-4">
 <input type="submit" name="action" class="btn" id="search" value="Voir informations" />
</form>

And when the user clicks the send button it goes to controller.php where I have:

case "Voir informations":
             $idActivite = $_POST['liste_formations'];
             $query = "SELECT * FROM formation WHERE idActivite = '$idActivite'";
             $result = mysqli_query($db, $query);
             while($row = mysqli_fetch_array($result))
             {
              $data["nombreMaxPart"] = $row["nombreMaxPart"];
              $data["idFormateur"] = $row["idFormateur"];
              $data["prix"] = $row["prix"];
              $data["description"] = $row["description"];
             }

             echo json_encode($data);
        break;

When I try to do that I get the information I want, but in a blank page with the information vector. I actually want to show it in a table.

  • `if(isset($_POST["idActivite"]))` is simply check if the given param exists and non null or empty.. if true then the code runs else the other code works. – danish-khan-I Aug 11 '19 at 20:36
  • take a look here https://stackoverflow.com/questions/17139501/using-post-to-get-select-option-value-from-html/17139538 – user8794331 Aug 11 '19 at 20:37
  • in controller.php, put the follow at the top of the page, submit the form and paste the results: echo '
    ' . print_r($_POST, true) . '
    ';
    – James P Aug 11 '19 at 20:57
  • I tried this echo '
    ' . print_r($_POST, true) . '
    '; thing and I got Array ( [liste_formations] => 64 [action] => Voir informations )
    – Maria Thereza Aug 11 '19 at 21:15

0 Answers0