Take the 2-minute tour ×

I have an issue that i need to learn how to solve! I'm making a submission form which consists of some select tags drop menus! so all of these drop menus are getting the data from the database i did that but the issue is that i need when i select something from Drop menu#1 i make a query and choose the matching data from the database and post them to Drop menu#2 ! so here is my code :-

echo "Choose your Source :<select name='source' value='Source'>
                      <option> </otpion>";
$sql = "SELECT City_name FROM city";
$info = mysql_query($sql);

while ($row = mysql_fetch_array($info)) {
    echo "<option > '" . @$row[0] . "'</option>";

echo "</select>";
echo "Choose your Destination :<select name='destination' value='Destination'>
                            <option> </otpion>";
echo @$source = $_POST['source'];
$sql = "SELECT Destination FROM Schedule  WHERE Source ='" . @$source . "'";
$info = mysql_query($sql);

while (@$row = mysql_fetch_array($info)) {
    echo "<option selected='selected'>'" . @$row['0'] . "'</option>";

echo "</select><br />";

so now all i want to know, how can i get values from the database into "destination" drop menu when i select a value from "source" drop menu without refreshing the page nor clicking any buttons! thanks in advance .

share|improve this question

closed as not constructive by markus, PeeHaa, EdChum, Lukas Knuth, Robert Rouhani Dec 30 '12 at 1:24


Honestly, from what source in the wild internet did you learn to write such code or where did you copy it from?? It's absolutely terrible! A mixture of PHP, HTML, SQL (bad), full of error supressors (bad), uses the mysql_* API (bad, deprecated), is vulnerable to SQL injection attacks (dangerous). –  markus Dec 29 '12 at 23:25
Forget everything you've learned about PHP and start again, here: phptherightway.com –  markus Dec 29 '12 at 23:29
@markus-tharkun what is this assault man? i am still learning!!! –  Mohammad99 Dec 30 '12 at 1:47
It's not an assault on you, it's outrage about the fact that there STILL exists such horrible stuff out there... –  markus Dec 30 '12 at 1:55
@markus-tharkun - It's comments like yours that detract many people from learning more about programming and that is sad. There is a way to provide feedback and constructive criticism and yours was not that way. More experienced programmers like yourself should encourage others who are new or struggling in order to foster a more positive and ultimately more collaborative environment. –  user985189 Dec 30 '12 at 1:57

1 Answer 1

up vote 0 down vote accepted

That will require client-side scripting, like JavaScript. It appears you may be wanting to use AJAX, which would leverage JavaScript and allow you to make a call to your PHP file(s) on the server (and ultimately you database) without causing the page to refresh.

If you aren't familiar with AJAX, I suggest you do some research. You're best bet would be to use a JavaScript library with AJAX functions already available - like jQuery: http://api.jquery.com/jQuery.ajax/

share|improve this answer
