2016-05-19 10 views
-3

データベースに3つのテーブルがあります(standardscoursesstudents)。 Fnamegenderstudentsから選択して、標準の「標準」と「コース」をドロップダウンから登録していますが、「送信」ボタンが機能していないようです。コードは以下の通りです。データベースのデータを表示できません

<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

1)質問に「php」と「mysql」とラベルを付ける必要があります。2)これらのSQLリクエストをPHPmyAdminなどのツールでテストしましたか? - 3)phpスクリプトごとにdbconnectを呼び出す必要があるのは、その間にデータベースへの接続を終了しない場合です – raphv

+0

ありがとうraphv-はいphpmyadminで質問したところ、 – Ketchup

+4

**危険**:あなたは[削除されました](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

答えて

0

方法としてポストとのformタグ内のinput要素を刻む:私は「コース」と「標準の仕事のためのドロップダウンのように、それがデータベースに接続されていると確信しています。 submit型の入力要素は、フォームの提出に使用されます。

+0

ありがとうございましたRajeshは

Ketchup

+0

このしかし、まだ動作しませんが、私はあなたの助けに感謝します – Ketchup

+0

ケチャップは、フォームが提出されていますか?送信ボタンをクリックした後にページがリロードされますか? –

0

投稿されたフォームデータには、そのデータにsubmitフィールドが含まれている場合にのみ、何かを実行します。

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

あなたが持っているしかし:

<input type="submit" name="submit" id="submit"/> 

あなたの価値を持っていないので、何もそれのためのフォームデータには含まれません送信ボタンを。

+0

ありがとうQuentin私は値= "提出"を追加しました...あなたはそれが動作するように欠けている/間違っていると思いますか? – Ketchup

関連する問題