我的数据库中有3个表(standards
,courses
,students
)。我想在Fname
表格中显示gender
和students
,这些表格已在选定的'标准'和'当然'从下拉列表 - 但是"提交"按钮似乎不起作用。代码如下所示。我确信它与数据库相关联,作为“课程”的下拉菜单。和'标准'工作:
<html>
<head>
<title>Courses</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<div id="container">
<div id="wrapper">
<h1> Students</h1>
<div id="data">
<form action="index.php" method="POST">
<select name="standards">
<option>Standard</option>
<?php
include 'includes/dbconnect.php';
$query1 = "SELECT * FROM standards";
$result1 = mysql_query($query1);
while($rows1 = mysql_fetch_array($result1)){
$standardID = $rows1['id'];
$rowsData1 = $rows1['standardName'];
?>
<option value="<?php echo $standardID; ?>">
<?php
echo $rowsData1; ?></option>
<?php
}
?>
</select>
</div>
<div id="data2">
<select name="courses">
<option>Courses</option>
<?php
$query2 = "SELECT * FROM courses";
$result2 = mysql_query($query2);
while($rows2 = mysql_fetch_array($result2)){
$coursesID = $rows2['id'];
$rowsData2 = $rows2['courseName'];
?>
<option value="<?php echo $courseID;?>">
<?php echo $rowsData2; ?></option> <?php }?>
</select>
</div>
<div id="submit">
<input type="submit" name="submit" id="submit" value="submit"/>
<table border="1" id="table1">
<tr>
<th>Student Name</th>
<th>Gender</th>
</tr>
<?php
if(isset($_POST['submit'])){
$standardName = $_POST['standards'];
$courseName = $_POST['courses'];
$query3 = "SELECT students.Fname, students.gender
FROM students
WHERE students.standardID = '$standardName'
AND students.courseID = '$courseName'";
$result3 = mysql_query($query3);
while($rows3 = mysql_fetch_array($result3)){
//$dataID = $rows3['id'];
$studentName = $rows3['FName'];
$gender = $rows3['gender'];
?>
<tr>
<td><?php echo $studentName; ?></td>
<td><?php echo $gender; ?></td>
<tr>
<?php
}
}
?>
</table>
</div>
</div>
</body>
</html>
答案 0 :(得分:0)
使用post作为方法在表单标记内标记输入元素。提交类型的输入元素用于提交表单。
答案 1 :(得分:0)
如果该数据包含submit
字段,则您只对提交的表单数据执行任何操作。
if(isset($_POST['submit'])){
但是你有:
<input type="submit" name="submit" id="submit"/>
您的提交按钮没有值,因此表格数据中不会包含任何内容。