Hi. 'm new to php..please help.. 'm working with dropdown and submit button.. the dropdown contains certain values..if the user selectes one option in dropdown and clicks submit button, values corresponding to the dropdown should be displayed in table format from the database. the file name is campus.php
'm attaching the code below..
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<form action="campus.php" method="POST">
<table width="878" height="48" border="0" align="center">
<tr>
<th width="107" scope="col">Campus</th>
<th width="755" scope="col">
<select name="campus" id="campus">
<option selected="selected" >Select</option>
<option value="1">Amritapuri</option>
<option value="2">Kochi </option>
<option value="3">Ettimadai</option>
<option value="4">Banglore</option>
<option value="5">Mysore</option>
</select>
<label>
<input type="submit" name="submit" id="submit" value="Submit" />
</label></th>
</tr>
</table>
</form>
<?php
if(isset($_POST['campus']))
{
$table =mysql_escape_string($_POST['campus']);
echo $table;
$con = mysql_connect("localhost","admissions","admission") or die('Connection error : ' . mysql_error());;
mysql_select_db("amritavarsham13", $con);
$result = mysql_query("select SNO,NAME,GENDER,ENROLLNO,YROFSTUDY,COURSE,CAMPUS,FACULTYINCHARGE,CONTACTNO from searchportal where CAMPUS='$table';") or die ("SQL Error" . mysql_error());
print "<center>Campuswise listing: $table</center>";
print "<table align=center border=1>\n";
print "<tr><td>SNO</td><td>NAME</td><td>GENDER</td><td>ENROLLNO</td><td>YROFSTUDY</td><td>FACULTYINCHARGE</td><td>CONTACTNO</td>";
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
print "\t<tr>\n";
foreach ($row as $col_value)
{
echo "\t\t<td>" . htmlentities($col_value) . "</td>\n";
}
echo "\t</tr>\n";
}
echo "</table><center>\n";
/*else
{
die("Could not enter data: ' . mysql_error()");
}
echo "Please enter the required fields\n"*/
mysql_close();
mysql_close($con);
}
?>
</body>
</html>