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 6137045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:40:41+00:00 2026-05-23T17:40:41+00:00

I am trying to use a dynamic select form to send information to a

  • 0

I am trying to use a dynamic select form to send information to a MySQL database. The user will be able to choose their school, and then select their major from within that school’s list (all retrieved from a MySQL table). I then want to send that information to a different table in the database to be stored.

This is what I have for the code thus far:

<select name="school">
  <php
  $sql = "SELECT school_name, school_id FROM school_table ORDER BY school_name";
  $query = mysql_query($sql,$conn);

  while($row = mysql_fetch_array($states))
    {
  echo ("<option value=$row[school_id]>$row[school_name]</option>");        
    }
  ?>
</select>

I don’t know how to make the second select, which would ideally recognize the school_id from the first table and match it with the corresponding school_id on the second table, which also lists the majors at that school. Also, I don’t know how to send the form when it is finally done to a MySQL table.

  • 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-23T17:40:42+00:00Added an answer on May 23, 2026 at 5:40 pm

    You could either use a simple form to submit the value from the combobox to the server (as HTTP POST or HTTP GET) and use the value as a variable in you SQL statement or you could use a simple AJAX request to send the necessary information to your php script. Anyway, your serverside code should look like this:

    //process.php
    $myRetrievedValue = $_POST["school"];
    $mySqlStm = "SELECT * FROM foo WHERE bar = '".mysql_escape_string($myRetrivedValue)."'";
    

    On the client side you code could look like this (using a simple form and no AJAX stuff):

    <form action="process.php" method="post">
    <select name="school">  
    <php  $sql = "SELECT school_name, school_id FROM school_table ORDER BY school_name";  
          $query = mysql_query($sql,$conn);  while($row = mysql_fetch_array($states))    {  
          echo ("<option value=$row[school_id]>$row[school_name]</option>");            }  ?>
    </select>
    <input name="" type="submit" />
    </form>
    

    Please remember: Whenever you use a user input in you query use prepared statements (or at least escape methods as above) to avoid SQL injections.

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

Sidebar

Related Questions

I am trying to use variables in my mysql statement so they will change
I've been trying to use a dynamic view in Kohana 3.2 without success. I'm
I am trying to use a strong ref cur with dynamic sql statment but
Using LINQ , I've been trying to use the System.Linq.Dynamic library in order to
I'm trying to use dynamic sets to handle the way Excel 2010 does subqueries
I'm trying to figure out how to use dynamic variables for my methods that
I'm trying to use the new room feature in Socket.io v.7 to create dynamic
I'm trying to create a dynamic select box in JavaScript with a range of
I'm trying to use Dapper simply to map my database tables to types in
hi i am trying to use dynamic array name . but when i run

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.