1

我想在表中显示数据的这段代码,代码中没有错误,但是即使查询具有我想要的结果,我仍然有一个空表,这里是更多理解的代码

<?php
$connectdb = mysql_connect('localhost','root','sara', true ) or die ("Not Connect");
 if (!$connectdb)
 {
    die('Could not connect :'. mysql_errno());
  }
 $selestdb  = mysql_select_db('iexa', $connectdb) or die ("not selected database");
  if (isset($_POST['examID'])) {
   $examID = $_POST['examID'];
   }
    echo $examID;
    echo "<br />";
   $query = mysql_query("SELECT  Question  , Choise_1  , Choise_2 , Choise_3 , Choise_4 , Correct_Answer
   FROM question_bank WHERE E_No='examID' ORDER BY Question asc") or die ("mysql error");
 echo "<table width='40%' border='1' cellpadding='5'>
  <tr>
    <td>Qusetion </td>
    <td>Choise 1</td>
    <td>Choise 2</td>
    <td>Choise 3</td>
    <td>Choise 4</td>
    <td>The correct answer</td>
    </tr>";
   echo $query;
  while ($row = mysql_fetch_assoc($query)){
 echo '
  <tr>
   <td>'.$row['Question'].'</td>
   <td>' .$row['Choise_1'].'</td>
    <td>' .$row['Choise_2'].'</td>
   <td>' .$row['Choise_3'].'</td>
   <td>' .$row['Choise_4'].'</td>
    <td>' .$row['Correct_Answer'].'</td>
    </tr>';
     };
     echo "</table>";
     mysql_close($connectdb);
     ?>
4

3 回答 3

1

问题可能出在E_No='examID'它应该是:

E_No='" . mysql_real_escape_string($_POST['examID']) . "'

如果它是整数值,您始终可以将其类型转换为整数。查询看起来像:

"SELECT  Question  , Choise_1  , Choise_2 , Choise_3 , Choise_4 , Correct_Answer FROM question_bank WHERE E_No='" . mysql_real_escape_string($_POST['examID']) . "' ORDER BY Question asc"
于 2012-04-27T17:53:00.207 回答
1

您正在寻找文字'examId'

试试这个:

$examID = mysql_real_escape_string($_POST['examID']);
$query = mysql_query("SELECT  Question  , Choise_1  , Choise_2 , Choise_3 , Choise_4 , Correct_Answer
FROM question_bank
WHERE E_No='$examID' ORDER BY Question asc");
#           ^ here
于 2012-04-27T17:53:12.977 回答
0

您是否尝试过替换或死亡(“mysql错误”);与或死(mysql_error());?

似乎考试 id 在开始时也需要一个 $。

于 2012-04-27T17:54:57.987 回答