title: Using if(isset($_POST['submit'])) to not display echo when script is open is not working
body: <p>I have a little problem with my <code>if(isset($_POST['submit']))</code> code. What I want is some echos and a table to not appear when the script is open but I do want it to show when the submit button for the form has been clicked. The problem is though that when I include the <code>if(isset($_POST['submit']))</code> function, when I click on the submit button it does not display the echos and the table at all. Why is this and can you help me out with this issue please.</p>
  
  <p>Below is the code:</p>
  
  <pre><code>    &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  
  &lt;title&gt;Exam Interface&lt;/title&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;p&gt;&lt;strong&gt;NOTE: &lt;/strong&gt;If a search box is left blank, then the form will search for all data under that specific field&lt;/p&gt;
  
  &lt;form action="exam_interface.php" method="post" name="sessionform"&gt;        &lt;!-- This will post the form to its own page"--&gt;
  &lt;p&gt;Session ID: &lt;input type="text" name="sessionid" /&gt;&lt;/p&gt;      &lt;!-- Enter Session Id here--&gt;
  &lt;p&gt;Module Number: &lt;input type="text" name="moduleid" /&gt;&lt;/p&gt;      &lt;!-- Enter Module Id here--&gt;
  &lt;p&gt;Teacher Username: &lt;input type="text" name="teacherid" /&gt;&lt;/p&gt;      &lt;!-- Enter Teacher here--&gt;
  &lt;p&gt;Student Username: &lt;input type="text" name="studentid" /&gt;&lt;/p&gt;      &lt;!-- Enter User Id here--&gt;
  &lt;p&gt;Grade: &lt;input type="text" name="grade" /&gt;&lt;/p&gt;      &lt;!-- Enter Grade here--&gt;
  &lt;p&gt;Order Results By: &lt;select name="order"&gt;
  &lt;option value="ordersessionid"&gt;Session ID&lt;/option&gt;
  &lt;option value="ordermoduleid"&gt;Module Number&lt;/option&gt;
  &lt;option value="orderteacherid"&gt;Teacher Username&lt;/option&gt;
  &lt;option value="orderstudentid"&gt;Student Username&lt;/option&gt;
  &lt;option value="ordergrade"&gt;Grade&lt;/option&gt;
  &lt;/select&gt;
  &lt;p&gt;&lt;input type="submit" value="Submit" /&gt;&lt;/p&gt;
  &lt;/form&gt;
  
  &lt;?php
  
  $username="xxx";
  $password="xxx";
  $database="mobile_app";
  
  mysql_connect('localhost',$username,$password);
  
  @mysql_select_db($database) or die("Unable to select database");
  
  $sessionid = isset ($_POST['sessionid']) ? $_POST['sessionid'] : "";
  $moduleid = isset ($_POST['moduleid']) ? $_POST['moduleid'] : "";
  $teacherid = isset ($_POST['teacherid']) ? $_POST['teacherid'] : "";
  $studentid = isset ($_POST['studentid']) ? $_POST['studentid'] : "";
  $grade = isset ($_POST['grade']) ? $_POST['grade'] : "";
  $orderfield = isset ($_POST['order']) ? $_POST['order'] : "";
  
  $sessionid = mysql_real_escape_string($sessionid);
  $moduleid = mysql_real_escape_string($moduleid);
  $teacherid = mysql_real_escape_string($teacherid);
  $studentid = mysql_real_escape_string($studentid);
  $grade = mysql_real_escape_string($grade);
  
  switch ($orderfield) {
      case 'ordersessionid': $orderfield = 'gr.SessionId';
      break;
      case 'ordermoduleid': $orderfield = 'm.ModuleId'; 
      break;
      case 'orderteacherid': $orderfield = 's.TeacherId';
      break;
      case 'orderstudentid': $orderfield = 'gr.StudentId'; 
      break;
      case 'ordergrade': $orderfield = 'gr.Grade';
      break;
  }
  
  $ordertable = $orderfield;
  
  $result = mysql_query("SELECT * FROM Module m INNER JOIN Session s ON m.ModuleId = s.ModuleId JOIN Grade_Report gr ON s.SessionId = gr.SessionId JOIN Student st ON gr.StudentId = st.StudentId WHERE ('$sessionid' = '' OR gr.SessionId = '$sessionid') AND ('$moduleid' = '' OR m.ModuleId = '$moduleid') AND ('$teacherid' = '' OR s.TeacherId = '$teacherid') AND ('$studentid' = '' OR gr.StudentId = '$studentid') AND ('$grade' = '' OR gr.Grade = '$grade') ORDER BY $ordertable ASC");
  
  $num=mysql_numrows($result);
  
  if(isset($_POST['submit'])){
  
  echo "&lt;p&gt;Your Search: &lt;strong&gt;Session ID:&lt;/strong&gt; "; if (empty($sessionid))echo "'All Sessions'"; else echo "'$sessionid'";echo ", &lt;strong&gt;Module ID:&lt;/strong&gt; "; if (empty($moduleid))echo "'All Modules'"; else echo "'$moduleid'";echo ", &lt;strong&gt;Teacher Username:&lt;/strong&gt; "; if (empty($teacherid))echo "'All Teachers'"; else echo "'$teacherid'";echo ", &lt;strong&gt;Student Username:&lt;/strong&gt; "; if (empty($studentid))echo "'All Students'"; else echo "'$studentid'";echo ", &lt;strong&gt;Grade:&lt;/strong&gt; "; if (empty($grade))echo "'All Grades'"; else echo "'$grade'"; "&lt;/p&gt;";
  
  echo "&lt;p&gt;Number of Records Shown in Result of the Search: &lt;strong&gt;$num&lt;/strong&gt;&lt;/p&gt;";
  
  echo "&lt;table border='1'&gt;
  &lt;tr&gt;
  &lt;th&gt;Student Id&lt;/th&gt;
  &lt;th&gt;Forename&lt;/th&gt;
  &lt;th&gt;Session Id&lt;/th&gt;
  &lt;th&gt;Grade&lt;/th&gt;
  &lt;th&gt;Mark&lt;/th&gt;
  &lt;th&gt;Module&lt;/th&gt;
  &lt;th&gt;Teacher&lt;/th&gt;
  &lt;/tr&gt;";
  
  while ($row = mysql_fetch_array($result)){
  
   echo "&lt;tr&gt;";
    echo "&lt;td&gt;" . $row['StudentId'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['Forename'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['SessionId'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['Grade'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['Mark'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['ModuleName'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['TeacherId'] . "&lt;/td&gt;";
    echo "&lt;/tr&gt;";
  }
  
  echo "&lt;/table&gt;";
  
  }
  
  mysql_close();
  
  
   ?&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Any help will be much appreciated, Thank You.</p>