1

My problem is that I try to load a drop down based on selection from previous drop down. I'm loading the values from database. but when I use $_get['emirate'] I'm not getting the value. It says the value is not set.

$data = mysql_query("SELECT * FROM emirate") 
        or die(mysql_error()); 

    Print "<table border cellpadding=3>"; 
    print"<tr><th><form method=get action='index.php'><select id=EMIRATE size=1><OPTION value=all>all</option>";
    while($info = mysql_fetch_array( $data )) 
    { 
        Print "<option value=". $info['em_name'] .">".$info['em_name']."</option>"; 
    }
    print"</select></form></th>";
    if(isset($_GET['EMIRATE'])){
        $name=$_GET['EMIRATE'];
        echo $name;

        $data = mysql_query("SELECT a_name FROM areas where em_id=(select em_id from emirate where em_name=\"".$name."\")") 
        or die(mysql_error());
        Print "<th><select name=AREAS size=1>";
        while($info = mysql_fetch_array( $data ))
        {
            Print "<option >".$info['a_name']."</option>";
        }
        print"</select></th>";
    }
2
  • it is not the answer of your question, but before you fix this problem, you should validate your html and validate it by w3c .... Commented Oct 17, 2012 at 8:01
  • 1
    $_GET['EMIRATE'] will imply you're having a parameter called EMIRATE in your URL, so it would look something like http://domain.com/yourScript?EMIRATE=someValue. Is that so? Commented Oct 17, 2012 at 8:02

3 Answers 3

3

I found out the problem.

I haven't put a submit button and hence my form wasn't getting submitted. And hence I wasn't getting any value from $_GET.

http://php.net/manual/en/reserved.variables.get.php

Now I get the results smoothly.

Sign up to request clarification or add additional context in comments.

Comments

1

which method are you using on your form on the previous page, post or get?

you can replace $_GET with $_REQUEST which retrieves values from both post and get.

4 Comments

$_GET. The action is redirected to the same page as the code is written. Is that a problem?? i new to php..
i guess you havent got me..my both dropdown codes are in same file..:(
yes I got that, but i need to see both dropdowns or the entire file.
I see now, but like @donald123 said you're missing the name property on your select tag.
1
<select id=EMIRATE size=1><OPTION value=all>all</option>

Please fix the HTML.... you miss to set the name attribute for your select...

<select id="EMIRATE" size="1" name="EMIRATE">
    <option value="all">all</option>
    ....

1 Comment

i have done that before. but then i got an error sayin i dont have an index name 'EMIRATE'. so i changed my 'name' to 'id'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.