I have a html php file. in this file i have a form containing two select boxes employee department and employee branch. if i click the employee department select box it should execute a sql query using onchange event and show the selected department. The php code and html code is in same file. i tried this code
file name : Search.php
<?php
include("config.php");
$dept= (isset($_POST['dept'])) ? $_POST['dept'] : '';
$branch= (isset($_POST['branch'])) ? $_POST['branch'] : '';
?>
<html>
<body>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" name="quick_search" id="quick_search" method = "POST" enctype="multipart/form-data">
<select size="1" name="dept" id="dept" onchange="this.form.submit();" <?php $sql = "SELECT * FROM users WHERE dept = '$dept'"; $qry = mysql_query($sql); ?>>
<option value="select">select</option>
<option value="purchase">purchase</option>
<option value="Sales">sales</option>
<option value="production">production</option>
<option value="accounts">accounts</option>
</select>
<select size="1" name="branch" id="branch" onchange="this.form.submit();" <?php $sql = "SELECT * FROM users WHERE branch = '$branch'"; $qry = mysql_query($sql); ?>>
<option value="select">select</option>
<option value="salem">salem</option>
<option value="chennai">chennai</option>
<option value="kovai">kovai</option>
<option value="namakkal">namakkal</option>
</select>
<?php
while($userdetails = mysql_fetch_array($qry))
{
$userfirstname = $userdetails['firstname'];
$userbranch = $userdetails['branch'];
$userdepartment = $userdetails['department'];
$usersalary = $userdetails['salary'];
}
?>
</form>
</body>
</html>