Sorry I'm new to these stuff but I am having a hard time about this. So I'll trying to create a php and mysql program which can view records from database server. In my form I have 2 dropdown list and 2 submit button, the first one the the list of "section" and submit button, and the second one is a list of "year level" and submit button again. If I select the section "A" and click submit button, it will display only the student's information that belongs only on section "A" and same as on "year level". I can't figure it out whenever i click the submit button, i can't view the records. I hope it made sense. Please do you have any idea to make it work? here is what I have so far--->

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>View</title>
</head>
<body>
<form action="view.php" method="POST">
<td> </td><label>By Section: </label>
<td> </td><select name="Section" value="<?php echo $Section; ?>">


<option value="a">A</option>


<option value="b">B</option>


<option value="c">C</option>


<option value="d">D</option>

</select>


<td> </td><input type="submit" value="GO" name="sec"/>




<td> </td><label>By Year: </label>
<select name="Year" value="<?php echo $Year; ?>">


<option value="1">First Year</option>


<option value="2">Second Year</option>


<option value="3">Third Year</option>


<option value="4">Fourth Year</option>

</select>


<td> </td><input type="submit" value="GO" name="year"/>




<?php

include('quiz1_connect.php');
mysql_connect("$server", "$user", "$pass")or die("cannot connect"); 
mysql_select_db("$db")or die("cannot select DB");

if (isset($_POST['sec']))
{
if (is_numeric($_POST['Section']))
{
$Section = $_POST['Section'];

$result = mysql_query("SELECT * FROM tblquiz1 WHERE SecName='$Section'") 
or die(mysql_error()); 



echo "<table border='1' cellpadding='10'>";
echo "<tr> <th>ID:</th> <th>First Name:</th> <th>Last Name:</th> <th>Year:</th> <th>Section:</th> </tr>";


while($row = mysql_fetch_array( $result )) {


echo "<tr>";
echo '<td>' . $row['IDNo'] . '</td>';
echo '<td>' . $row['FName'] . '</td>';
echo '<td>' . $row['LName'] . '</td>';
echo '<td>' . $row['YearLvl'] . '</td>';
echo '<td>' . $row['SecName'] . '</td>';
echo "</tr>"; 
} 


echo "</table>";

}
}
?>
</form>
</body>
</html>

You need to seperate the two options into two forms than have if statements to display the results depending on what was selected:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>View</title>
</head>
<body>
<form action="view.php" method="POST">
<td> </td><label>By Section: </label>
<td> </td><select name="Section" value="<?php echo $Section; ?>">


<option value="a">A</option>


<option value="b">B</option>


<option value="c">C</option>


<option value="d">D</option>

</select>


<td> </td><input type="submit" value="GO" name="sec"/>

</form>

<form action="view.php" method="POST">

<td> </td><label>By Year: </label>
<select name="Year" value="<?php echo $Year; ?>">


<option value="1">First Year</option>


<option value="2">Second Year</option>


<option value="3">Third Year</option>


<option value="4">Fourth Year</option>

</select>


<td> </td><input type="submit" value="GO" name="year"/>

</form>




<?php

  include('quiz1_connect.php');
  mysql_connect("$server", "$user", "$pass")or die("cannot connect"); 
  mysql_select_db("$db")or die("cannot select DB");


if (isset($_POST['sec']))
{

  $Section = $_POST['Section'];

  $query = "SELECT * FROM tblquiz1 WHERE SecName='$Section'";
}

if (isset($_POST['year']))
{

  $Year = $_POST['Year'];

  $query = "SELECT * FROM tblquiz1 WHERE YearLvl='$Year'";

}

if (isset($query))
{

  $result = mysql_query($query) or die(mysql_error()); 

  
  echo "<table border='1' cellpadding='10'>";
  echo "<tr> <th>ID:</th> <th>First Name:</th> <th>Last Name:</th> <th>Year:</th> <th>Section:</th> </tr>";


  while($row = mysql_fetch_array( $result )) {


    echo "<tr>";
    echo '<td>' . $row['IDNo'] . '</td>';
    echo '<td>' . $row['FName'] . '</td>';
    echo '<td>' . $row['LName'] . '</td>';
    echo '<td>' . $row['YearLvl'] . '</td>';
    echo '<td>' . $row['SecName'] . '</td>';
    echo "</tr>"; 
  } 


  echo "</table>";


}


?>

</body>
</html>

Only submit button should be identified for one form. No matter how much submit buttons are you using within the same form, they've only submission of that form.

Try what @Glider Pilot mentioned above.

Oh. It works! Thank you so much guys! especially Sir GliderPilot, thank you. really. :))

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.