Click here to Skip to main content
15,895,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm having trouble with my dynamic select forms. When the "subject" form is submitted it works perfectly, but when the "course" form is then submitted, the form seems to submit properly (localhost/page.php?subject=1&course=2), but it returns the option back to null so it isn't working with later php that is dependent on the course_id.
$subject = $course = null;

$conn = mysql_connect('', '', '');
$db = mysql_select_db('',$conn);

if(isset($_GET["subject"]) && is_numeric($_GET["subject"]))
{
     $subject = $_GET["subject"];
}

if(isset($_GET["course"]) && is_numeric($_GET["course"]))
{
     $country = $_GET["course"];
}
?>

<script language="JavaScript">

function autoSubmit()
{
     var formObject = document.forms['theForm'];
     formObject.submit();
}

</script>

<form name="theForm" method="get">
    <select name="subject"  önChange="autoSubmit();">
        <option value="null">Select a Subject...</option>

                $sql = "SELECT DISTINCT subj_name, subj_id FROM table1 ".
                 " ORDER BY subj_name";
        $result = mysql_query($sql) or die ("couldn't execute query");

        while($row = mysql_fetch_array($result))
        {
            echo ("<option value=\"$row[subj_id]\" " . 
                 ($subject == $row["subj_id"] ? " selected" : "") . 
                  ">$row[subj_name]</option>");        
        }
        ?>          
    </select>

if($subject != null && is_numeric($subject))
{
?>

    <select name="course"  önChange="autoSubmit();">        
        <option value="null">Select a Course...</option>

                $sql = "SELECT DISTINCT course_id, course_name, subj_id FROM table1 ".
                  "WHERE subj_id = $subject";
        $result = mysql_query($sql);

        while($row = mysql_fetch_array($result))
        {
            echo ("<option value=\"$row[course_id]\" " . 
                     ($course == $row["course_id"] ? " selected" : "") . 
                  ">$row[course_name]</option>");        
        }
        ?>          
    </select>

}
?>
</form>
Posted
Comments
Uday P.Singh 17-Jul-11 12:38pm    
not clear, what's the issue?
shakil0304003 17-Jul-11 23:38pm    
Not Clear!!!

1 solution

I think the problem is probably here:
PHP
if(isset($_GET["course"]) && is_numeric($_GET["course"]))
{
     $country = $_GET["course"];
}


- you have $country = instead of $course = .
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900