データベースに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>
1)質問に「php」と「mysql」とラベルを付ける必要があります。2)これらのSQLリクエストをPHPmyAdminなどのツールでテストしましたか? - 3)phpスクリプトごとにdbconnectを呼び出す必要があるのは、その間にデータベースへの接続を終了しない場合です – raphv
ありがとうraphv-はいphpmyadminで質問したところ、 – Ketchup
**危険**:あなたは[削除されました](http://php.net/manual/en/mysql.php)[[**廃止**データベースAPI](http://stackoverflow.com/q/12859942/19068)を使用しています)PHPから。 [現代的な代替品](http://php.net/manual/en/mysqlinfo.api.choosing.php)を選択する必要があります。あなたは** [SQLインジェクション攻撃](http://bobby-tables.com/)**に対して脆弱です**現代のAPIは、[防御]を容易にします(http://stackoverflow.com/questions/60174/最良の方法からSQLへのPHPインジェクション)をあなた自身から守ってください。 – Quentin