Sara S'h
Sara S'h

Reputation: 85

no data in the table

ive this code where i want to show data in a table , there is no error in the code , but i keep having an empty table even though the query has the result that i want , here is the code for more understanding

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

Upvotes: 1

Views: 83

Answers (3)

ODelibalta
ODelibalta

Reputation: 2244

Have you tried replacing or die ("mysql error"); with or die(mysql_error()); ?

Seems like exam id needs a $ at the beginning as well.

Upvotes: 0

Quassnoi
Quassnoi

Reputation: 425331

You are searching for literal 'examId'

Try this:

$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

Upvotes: 1

vedarthk
vedarthk

Reputation: 1333

The problem might be at E_No='examID' it should be:

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

You can always typecast it to integer if it is an integer value. The query would look like :

"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"

Upvotes: 1

Related Questions