title: html select option tag in php (oracle database)
body: <p>I have a problem making a select tag in php code dynamic. I'm creating a website (homework) using php and connecting to an oracle database which has all the info needed. Each <code>agency</code> has a list of <code>vehicules</code>.</p>
  
  <p>I created a <code>select option</code> tag for <code>agencies</code> and for <code>vehicules</code>. I want the data for vehicules to change depending on what agency the user chooses. So if the user chooses <code>agency A</code>, the vehicules that should be available on the <code>select option</code> tag for vehicules should be that of <code>agency A1</code> and no other agency. So far I have all the vehicules of all the agencies in the <code>select</code> tag. </p>
  
  <p>I tried creating a function that checks the user's input an selects the vehicule from the agency the user chose. Then it initialise a <code>$query</code> in function. And then use that query to fill in my <code>select</code> tag. Here is the code</p>
  
  <pre><code>function chooseVehicule(){
                      if( ($_POST['agence'])=='CARPORT'){
                          $query='SELECT marque, modele, nom_agence, num_immatriculation from vehicules v, agences ag
                                  WHERE v.id_agence=ag.id_agence
                                  AND ag.nom_agence=="CARPORT"';
                      }
                  }
  </code></pre>
  
  <p>then </p>
  
  <pre><code>chooseVehicule();
  </code></pre>
  
  <p>But it gives me <code>Undefined index: agence</code> error.
  Any ideas please? Here is my complete code.</p>
  
  <pre><code>&lt;?php
  
                  function chooseVehicule(){
                      if( ($_POST['agence'])=='CARPORT'){
                          $query='SELECT v.marque, modele, ag.nom_agence, v.num_immatriculation from vehicules v, agences ag
                                  WHERE v.id_agence=ag.id_agence
                                  AND ag.nom_agence=="CARPORT"';
                      }
                  }
          echo '&lt;h3&gt;'; echo 'Pour la location d\'une vehicule, veuillez remplir ce formulaire';echo'&lt;/h3&gt;';
  
  
                 /*CLIENTS*/
                 $query="SELECT nom_client from CLIENTS";
                 $state=oci_parse($conn, $query);
                 oci_execute($state, OCI_COMMIT_ON_SUCCESS);
  
                 echo '
                     &lt;form action="location.php" method="post"&gt;
                     &lt;p&gt;&lt;label for="client"&gt;Select your Name&lt;/label&gt;
                     &lt;select name="client" id="client"&gt;';
  
                 while(($row = oci_fetch_array($state, OCI_BOTH))){
                     echo'&lt;option value="'.$row[0].'"&gt;'.$row[0]; echo'&lt;/option&gt;';
                 }
                 echo'&lt;/select&gt;&lt;/p&gt;'; 
                 echo '&lt;/form&gt;';
  
  
                 /*AGENCES*/
          $query="SELECT nom_agence from AGENCES";
          $state=oci_parse($conn, $query);
                  oci_execute($state, OCI_COMMIT_ON_SUCCESS);
                  echo '
                      &lt;form action="location.php" method="post"&gt;
                          &lt;p&gt;&lt;label for="agence"&gt;Select a Company&lt;/label&gt;
                          &lt;select name="agence" id="agence"&gt;';
  
                          while(($row = oci_fetch_array($state, OCI_BOTH))){
                              echo '&lt;option value="'.$row[0].'"&gt;'.$row[0]; echo'&lt;/option&gt;';
                          }
  
                      echo '&lt;/select&gt;&lt;/p&gt;';
                      echo '&lt;/form&gt;';
  
  
                  /*VEHICULES*/
  
                 $query="SELECT marque, modele, nom_agence, num_immatriculation from vehicules v, agences ag
                         WHERE v.id_agence=ag.id_agence
                         AND type_vehicule='UTILITAIRE'
                         order by nom_agence";
  
                 $state=oci_parse($conn, $query);
                 oci_execute($state, OCI_COMMIT_ON_SUCCESS);
  
                 echo '
                     &lt;form action="location.php" method="post"&gt;
                     &lt;p&gt;&lt;label for="vehicule"&gt;Select a Vehicule&lt;/label&gt;
                     &lt;select name="vehicule" id="vehicule"&gt;';
                 echo '&lt;optgroup label="Utilitaire"&gt;';
                 while(($row = oci_fetch_array($state, OCI_BOTH))){
                     echo '&lt;option value="'.$row[3].'"&gt;'.$row[2]. ' ' . $row[0] . ' ' . $row[1]; echo '&lt;/option&gt;';
                 }
                 echo '&lt;/optgroup&gt;';
  
                 $query="SELECT v.marque, v.modele, ag.nom_agence, v.num_immatriculation from vehicules v, agences ag
                         WHERE v.id_agence=ag.id_agence
                         AND type_vehicule='VOITURE'
                         order by nom_agence";
  
                 echo '&lt;optgroup label="Voiture"&gt;';
                 $state=oci_parse($conn, $query);
                 oci_execute($state, OCI_COMMIT_ON_SUCCESS);
                 while(($row = oci_fetch_array($state, OCI_BOTH))){
                     echo '&lt;option value="'.$row[3].'"&gt;'.$row[2]. ' ' . $row[0] . ' ' . $row[1]; echo '&lt;/option&gt;';
                 }
                 echo '&lt;/optgroup&gt;';
  
                 echo'&lt;/select&gt;&lt;/p&gt;'; 
                 echo '&lt;/form&gt;';
  
      oci_free_statement($state);
      oci_close($conn);
          ?&gt;
  </code></pre>
  
  <p>I didn't use the function <code>chooseVehicule</code> since it gives me an error. 
  Thanks.</p>