php - 表中没有数据

标签 php mysql html

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

<?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);
     ?>

最佳答案

问题可能在 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"

关于php - 表中没有数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10355427/

相关文章:

php - 如何使用 $http.get 有效地轮询 mySQL 数据库

php - 在 zend 框架中包含 js 文件的最佳方式

java - 优化MySQL更新查询

mysql - 在mysql数据库中存储时区信息

html - 并排 Div 没有对齐

html - 移动设备上的响应式 Web 问题

php - 使用 SFTP 和 PHP 或 shell/终端脚本传输文件

php - 设置内容相对于侧边栏的位置

mysql - 如何使用--skip-grant-tables 启动 MySQL?

javascript - 如何从 javascript 方法中获取值并分配给 header 字段