Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6803507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:21:10+00:00 2026-05-26T19:21:10+00:00

I have a problem making a select tag in php code dynamic. I’m creating

  • 0

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 agency has a list of vehicules.

I created a select option tag for agencies and for vehicules. I want the data for vehicules to change depending on what agency the user chooses. So if the user chooses agency A, the vehicules that should be available on the select option tag for vehicules should be that of agency A1 and no other agency. So far I have all the vehicules of all the agencies in the select tag.

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 $query in function. And then use that query to fill in my select tag. Here is the 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"';
                    }
                }

then

chooseVehicule();

But it gives me Undefined index: agence error.
Any ideas please? Here is my complete code.

<?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 '<h3>'; echo 'Pour la location d\'une vehicule, veuillez remplir ce formulaire';echo'</h3>';


               /*CLIENTS*/
               $query="SELECT nom_client from CLIENTS";
               $state=oci_parse($conn, $query);
               oci_execute($state, OCI_COMMIT_ON_SUCCESS);

               echo '
                   <form action="location.php" method="post">
                   <p><label for="client">Select your Name</label>
                   <select name="client" id="client">';

               while(($row = oci_fetch_array($state, OCI_BOTH))){
                   echo'<option value="'.$row[0].'">'.$row[0]; echo'</option>';
               }
               echo'</select></p>'; 
               echo '</form>';


               /*AGENCES*/
        $query="SELECT nom_agence from AGENCES";
        $state=oci_parse($conn, $query);
                oci_execute($state, OCI_COMMIT_ON_SUCCESS);
                echo '
                    <form action="location.php" method="post">
                        <p><label for="agence">Select a Company</label>
                        <select name="agence" id="agence">';

                        while(($row = oci_fetch_array($state, OCI_BOTH))){
                            echo '<option value="'.$row[0].'">'.$row[0]; echo'</option>';
                        }

                    echo '</select></p>';
                    echo '</form>';


                /*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 '
                   <form action="location.php" method="post">
                   <p><label for="vehicule">Select a Vehicule</label>
                   <select name="vehicule" id="vehicule">';
               echo '<optgroup label="Utilitaire">';
               while(($row = oci_fetch_array($state, OCI_BOTH))){
                   echo '<option value="'.$row[3].'">'.$row[2]. ' ' . $row[0] . ' ' . $row[1]; echo '</option>';
               }
               echo '</optgroup>';

               $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 '<optgroup label="Voiture">';
               $state=oci_parse($conn, $query);
               oci_execute($state, OCI_COMMIT_ON_SUCCESS);
               while(($row = oci_fetch_array($state, OCI_BOTH))){
                   echo '<option value="'.$row[3].'">'.$row[2]. ' ' . $row[0] . ' ' . $row[1]; echo '</option>';
               }
               echo '</optgroup>';

               echo'</select></p>'; 
               echo '</form>';

    oci_free_statement($state);
    oci_close($conn);
        ?>

I didn’t use the function chooseVehicule since it gives me an error.
Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:21:11+00:00Added an answer on May 26, 2026 at 7:21 pm

    The keys in the $_POST superglobal will be sent to the server with the same names as the form fields. If this form is submitting to itself, you will need to send a field with the name agence to avoid this error. PHP is throwing the error because there is no key agence in the $_POST array.

    In order to bypass this check, since this page is processing numerous forms, you can isset each key first before running a check against it:

    if( isset($_POST['agence']) && $_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"';
                        }
    

    You should do this for all the forms that are sent selectively.

    EDIT:

    You’re going to need to put some state into the page, ‘state’ in the sense of how far the user has gotten into the selection process. Let’s make it so that the form for vehicles only shows if the user has already selected an agency. This form should be wrapped in a conditional.

    wrap all the logic for the vehicles form in this conditional:

    if(isset($_POST['agence'])){
      $query="SELECT nom_agence from AGENCES";
        $state=oci_parse($conn, $query);
                oci_execute($state, OCI_COMMIT_ON_SUCCESS);
                echo '
                    <form action="location.php" method="post">
                        <p><label for="agence">Select a Company</label>
                        <select name="agence" id="agence">';
    
                        while(($row = oci_fetch_array($state, OCI_BOTH))){
                            echo '<option value="'.$row[0].'">'.$row[0]; echo'</option>';
                        }
    
                    echo '</select></p>';
                    echo '</form>';
    }
    

    Since this page is procedural, this will make it so that after a selection is made for the agency, then and only then will the vehicle form appear.

    We’re going to need to make the query for vehicles have a WHERE clause that reflects the selection that was made by the user. It looks as though you are joining for the id across two tables so the where clause will either need to lookup by agency id or agency name, depending on the database design.

    If the vehicle form is put in the conditional like this, we can be certain the user has already made a selection of agency and progressed to the second “state” of the form. You’ll need to then parameterize your sql statement and pass in the selected id.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a simple Dynamic Website using PHP, where i allow the user
I'm making a shopping mall website using a Yahoo solution. I have multiple options
I'm currently making my own social network and I have a php problem which
My only problem is making them line up three-across and have equal spacing. Apparently,
I am making an application with Java Swing and i have a problem. I
I have a very big problem. I am making a CRM (Costumer Relationship Management)
I have a tiny (rikiki) problem in SWT ... I am making a small
Here is my problem. I have created a pretty heavy readonly class making many
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have this bizarre problem. I'm making a checklist program with XCode and I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.