2016-07-15 9 views
-2

私はsNumberから新しいPHPページを開き、sNumberからstudent profileページのstudentテーブルのデータを表示しようとしています。しかし、私はデータを取得することはできません、それはエラーに右に行く。どんな助けもありがとう。おかげ私のMySQLデータベースに情報が表示されない

studentlist.php

<div class="memtable"> 
     <?php 
     $reload = $_SERVER['PHP_SELF'] . "?tpages=" . $tpages; 
     echo '<div class="pagination"><ul>'; 
     if ($total_pages > 1) { 
      echo paginate($reload, $show_page, $total_pages); 
     } 
     echo "</ul></div>"; 
     // display data in table 
     echo "<table class='table table-bordered'>"; 
     echo "<thead><tr><th>Last Name</th> <th>First Name</th> <th>School</th> <th>Snumber</th></tr></thead>"; 
     // loop through results of database query, displaying them in the table 
     for ($i = $start; $i < $end; $i++) { 
      // make sure that PHP doesn't try to show results that don't exist 
      if ($i == $total_results) { 
       break; 
      } 

       // echo out the contents of each row into a table 
       $lastName = "<a href = 'studentprofile.php?id= " .mysql_result($result, $i, 'sNumber'). "'>" . mysql_result($result, $i, 'lastName') . "</a>"; 

       echo "<tr " . $cls . ">"; 
       echo '<td>' . $lastName . '</td>'; 
       echo '<td>' . mysql_result($result, $i, 'firstName') . '</td>'; 
       echo '<td>' . mysql_result($result, $i, 'school') . '</td>'; 
       echo '<td>' . mysql_result($result, $i, 'sNumber') . '</td>'; 
       echo "</tr>"; 
     } 
     // close table> 
     echo "</table>"; 
     // pagination 
     ?> 
    </div> 

studentprofile.php

<?php 

    include('phpdocs/connect.inc.php'); 
    include('header.php'); 


    if (isset($_GET[ "sNumber" ])) 
    $student_sNumber = $_GET['sNumber']; 

    $getStudentInfo = " SELECT sNumber FROM student WHERE student.sNumber = " . $student_sNumber; 
?> 

<!DOCTYPE html> 
    <html> 
    <head> 
    <title>Student</title> 
    <link href="css/style.css" rel="stylesheet" type="text/css"> 
    </head> 
    <body> 
    <div class="transoverlay"> 

    <?php 
    if ($result = mysql_query($getStudentInfo)) { 
    /* fetch associative array */ 
    while ($row = mysql_fetch_assoc($result)) { 

     echo "<h1 class='tv'>" . $row["sNumber"]. ", ". $row['firstName']."</h1>"; 
    } 

    mysql_free_result($result); 

}else{ 

    echo "<div class='tv'>Student Data could not be listed. </div>"; 
} 



    ?> 

    <hr color="#1a1a1a"> 


    </div> 

    </body> 
    <?php include('footer.php');?> 
    </html> 
+0

'$ _GET ['sNumber']'は設定されていないので、クエリが失敗するようですが、正直なところ、このスクリプトでは多くの問題が発生する可能性があります。 GoogleのPDOも – bassxzero

+0

@bassxzeroありがとうございます。私はPDOを調べます – kaydrae

+0

[mysql_ *]を使用しないでください(http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php?rq=1) ; mysql_ *関数は時代遅れであり、非推奨です(http://us3.php.net/manual/en/intro.mysql.php)。 ['MySQLi'](http://us3.php.net/manual/en/book.mysqli.php)または[' PDO'](http://us3.php.net/manual/en/intro。 pdo.php)を使用してください。また、あなたは[** SQLインジェクション**](https://www.owasp.org/index.php/SQL_Injection)を広く利用することができます。準備されたステートメントを使用し、適切に使用する必要があります。このスクリプトでは多くのことを修正する必要があります。 –

答えて

2

urlはidを使用していますが、sNumber変更のためにあなたが学生番号を引用する必要があり、それらの

のいずれかをチェックします文字列としてのクエリ

$getStudentInfo = "SELECT sNumber FROM student WHERE student.sNumber ='". $student_sNumber."'"; 
+0

idをsNumberに変更しましたが、動作しませんでした。 – kaydrae

+0

ページ(studentprofile.php)のURLはどのように表示されますか? –

+0

「学生データをリストできませんでした」というエラーが表示されます – kaydrae

関連する問題