Asked  2 Years ago    Answers:  5   Viewed   74 times

I have a little problem with my if(isset($_POST['submit'])) 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 if(isset($_POST['submit'])) 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.

Below is the code:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">

<title>Exam Interface</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<p><strong>NOTE: </strong>If a search box is left blank, then the form will search for all data under that specific field</p>

<form action="exam_interface.php" method="post" name="sessionform">        <!-- This will post the form to its own page"-->
<p>Session ID: <input type="text" name="sessionid" /></p>      <!-- Enter Session Id here-->
<p>Module Number: <input type="text" name="moduleid" /></p>      <!-- Enter Module Id here-->
<p>Teacher Username: <input type="text" name="teacherid" /></p>      <!-- Enter Teacher here-->
<p>Student Username: <input type="text" name="studentid" /></p>      <!-- Enter User Id here-->
<p>Grade: <input type="text" name="grade" /></p>      <!-- Enter Grade here-->
<p>Order Results By: <select name="order">
<option value="ordersessionid">Session ID</option>
<option value="ordermoduleid">Module Number</option>
<option value="orderteacherid">Teacher Username</option>
<option value="orderstudentid">Student Username</option>
<option value="ordergrade">Grade</option>
<p><input type="submit" value="Submit" /></p>




@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';
    case 'ordermoduleid': $orderfield = 'm.ModuleId'; 
    case 'orderteacherid': $orderfield = 's.TeacherId';
    case 'orderstudentid': $orderfield = 'gr.StudentId'; 
    case 'ordergrade': $orderfield = 'gr.Grade';

$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");



echo "<p>Your Search: <strong>Session ID:</strong> "; if (empty($sessionid))echo "'All Sessions'"; else echo "'$sessionid'";echo ", <strong>Module ID:</strong> "; if (empty($moduleid))echo "'All Modules'"; else echo "'$moduleid'";echo ", <strong>Teacher Username:</strong> "; if (empty($teacherid))echo "'All Teachers'"; else echo "'$teacherid'";echo ", <strong>Student Username:</strong> "; if (empty($studentid))echo "'All Students'"; else echo "'$studentid'";echo ", <strong>Grade:</strong> "; if (empty($grade))echo "'All Grades'"; else echo "'$grade'"; "</p>";

echo "<p>Number of Records Shown in Result of the Search: <strong>$num</strong></p>";

echo "<table border='1'>
<th>Student Id</th>
<th>Session Id</th>

while ($row = mysql_fetch_array($result)){

 echo "<tr>";
  echo "<td>" . $row['StudentId'] . "</td>";
  echo "<td>" . $row['Forename'] . "</td>";
  echo "<td>" . $row['SessionId'] . "</td>";
  echo "<td>" . $row['Grade'] . "</td>";
  echo "<td>" . $row['Mark'] . "</td>";
  echo "<td>" . $row['ModuleName'] . "</td>";
  echo "<td>" . $row['TeacherId'] . "</td>";
  echo "</tr>";

echo "</table>";





Any help will be much appreciated, Thank You.



You need to give your submit <input> a name or it won't be available using $_POST['submit']:

<p><input type="submit" value="Submit" name="submit" /></p>
Wednesday, August 24, 2022

You didn't mentioned the phone number field, so I assumed is phone_number:

$db = new PDO('mysql:host=localhost;dbname=testdb;charset=UTF-8', 'username', 'password', array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));

if (isset($_REQUEST['data'])){
    $data = json_decode($_REQUEST['data']);
        $stmt = $db->prepare("SELECT `id` FROM `test` where `id`=:phone_number");
        $stmt->execute(array(':phone_number' => $data->phonenumber));
        $row_count = $stmt->rowCount();

        if($row_count && ($data->phonenumber != '')){
            $stmt = $db->prepare("UPDATE `test` SET `longitude`=:longitude, `latitude`=:latitude, `timestamp`=:timestamp WHERE `id`=:phone_number");
            $stmt->execute(array(':longitude' => $data->longitude,':latitude' => $data->latitude,':timestamp' => $data->timestamp,':phone_number' => $data->phonenumber));
Thursday, September 22, 2022

This will do the trick:


$con = mysql_connect( "localhost", "site", "xxxxxxxx" );
if ( !$con ) {
    die('Could not connect: ' . mysql_error());

mysql_select_db("site", $con);

1st, remove the sql injection part at least like this:

$firstname = strip_tags( $_POST[ 'firstname' ] );
$surname = strip_tags( $_POST[ 'surname' ] );

2nd, I didn't change it, but you need to remove the * and enter only specific values you want to load. Even if those are all the values, still write them manually.

$query = "SELECT * FROM Members WHERE firstname='" . $firstname . "' and surname=' " . $surname. "'";  
$result = mysql_query( $query );

3rd, you can check for row count, if you got some value, there is an entry with those variables

if ( mysql_num_rows($result) >= 1 ) {
    // the page you want
} else {
    // redirect user to another page
    header( "Location: signup.php" ); die;



Think adding some unique requests to your query. What will happen if two users have identical names and surnames or if a new one wants to join, but the name and lastname is already in the db ...

Thursday, December 15, 2022

Replacing body and subject should help you:

function emailpage() {
    strTitle = document.title;
    strTitle = strTitle.replace("&","-");
    window.location = "mailto:?body=" + strTitle + " - " + window.location + "&subject=I thought this link might interest you.";
Wednesday, September 14, 2022

It's simply because Windows sees that the monitor has now been disconnected and you have one less monitor available. Therefore it'll try to move windows on that screen to the visible ones

It's not related to the connection type but whether the monitor chooses to leave the connection active while it was being turned off or not. I've seen the behavior on both display port and HDMI.

For example many TVs leave their HDMI ports on while they're in standby mode or showing another source, therefore the OS thinks that the monitor is still on even though the screen is invisible. As a result it leaves the multi-monitor configuration as-is. The same thing happened with some of my display port monitors. But some others turn the signal off right after I press the power button, which results in what you observe

That phenomenon applies to even VGA cables. You may see that in your case but that doesn't mean it always works like that. The VGA port doesn't maintain an active connection without DDC, so the PC can't reliably detect whether a monitor was attached or not. That's the reason why sometimes the proper resolution can't be obtained due to a bad cable or an ancient monitor and the output will be distorted/squeezed/whatever

See also

  • How does a PC detect a VGA monitor?
  • Is VGA port hot-pluggable?
  • My computer doesn't recognize the monitor's resolution on some VGA cables, what's going on?
  • Disable 'Monitor Off' detection, how?
Wednesday, October 5, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :

Browse Other Code Languages