search
HomeDatabaseMysql TutorialWhy is my `if(isset($_POST['submit']))` Not Hiding the Echo and Table on Page Load?

Why is my `if(isset($_POST['submit']))` Not Hiding the Echo and Table on Page Load?

Why if(isset($_POST['submit'])) is Not Working to Hide Echos and Table on Page Load

Problem Description

The if(isset($_POST['submit'])) statement is intended to hide specified echos and a table when the script is initially opened. However, after implementing this code, users report that the echos and table are still visible even after the submit button is clicked.

Solution

The issue arises because the submit button is not assigned a unique name in the code provided. To remedy this, the button should be given a name, as seen in the corrected code below:

<p><input type="submit" value="Submit" name="submit"></p>

With this modification, the if(isset($_POST['submit'])) statement will correctly detect when the submit button has been clicked and perform the intended actions to hide the desired elements.

Moreover, the original code missed the database connectivity codes that connect to the database. For better understanding, the corrected and complete code is as follows:

<?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 "<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'";
    "";

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

    echo "
"; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; while ($row = mysql_fetch_array($result)) { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } echo "
Student IdForenameSession IdGradeMarkModuleTeacher
" . $row['StudentId'] . "" . $row['Forename'] . "" . $row['SessionId'] . "" . $row['Grade'] . "" . $row['Mark'] . "" . $row['ModuleName'] . "" . $row['TeacherId'] . "
"; } mysql_close(); ?>

The above is the detailed content of Why is my `if(isset($_POST['submit']))` Not Hiding the Echo and Table on Page Load?. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
MySQL: BLOB and other no-sql storage, what are the differences?MySQL: BLOB and other no-sql storage, what are the differences?May 13, 2025 am 12:14 AM

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

MySQL Add User: Syntax, Options, and Security Best PracticesMySQL Add User: Syntax, Options, and Security Best PracticesMay 13, 2025 am 12:12 AM

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

MySQL: How to avoid String Data Types common mistakes?MySQL: How to avoid String Data Types common mistakes?May 13, 2025 am 12:09 AM

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

MySQL: String Data Types and ENUMs?MySQL: String Data Types and ENUMs?May 13, 2025 am 12:05 AM

MySQloffersechar, Varchar, text, Anddenumforstringdata.usecharforfixed-Lengthstrings, VarcharerForvariable-Length, text forlarger text, AndenumforenforcingdataAntegritywithaetofvalues.

MySQL BLOB: how to optimize BLOBs requestsMySQL BLOB: how to optimize BLOBs requestsMay 13, 2025 am 12:03 AM

Optimizing MySQLBLOB requests can be done through the following strategies: 1. Reduce the frequency of BLOB query, use independent requests or delay loading; 2. Select the appropriate BLOB type (such as TINYBLOB); 3. Separate the BLOB data into separate tables; 4. Compress the BLOB data at the application layer; 5. Index the BLOB metadata. These methods can effectively improve performance by combining monitoring, caching and data sharding in actual applications.

Adding Users to MySQL: The Complete TutorialAdding Users to MySQL: The Complete TutorialMay 12, 2025 am 12:14 AM

Mastering the method of adding MySQL users is crucial for database administrators and developers because it ensures the security and access control of the database. 1) Create a new user using the CREATEUSER command, 2) Assign permissions through the GRANT command, 3) Use FLUSHPRIVILEGES to ensure permissions take effect, 4) Regularly audit and clean user accounts to maintain performance and security.

Mastering MySQL String Data Types: VARCHAR vs. TEXT vs. CHARMastering MySQL String Data Types: VARCHAR vs. TEXT vs. CHARMay 12, 2025 am 12:12 AM

ChooseCHARforfixed-lengthdata,VARCHARforvariable-lengthdata,andTEXTforlargetextfields.1)CHARisefficientforconsistent-lengthdatalikecodes.2)VARCHARsuitsvariable-lengthdatalikenames,balancingflexibilityandperformance.3)TEXTisidealforlargetextslikeartic

MySQL: String Data Types and Indexing: Best PracticesMySQL: String Data Types and Indexing: Best PracticesMay 12, 2025 am 12:11 AM

Best practices for handling string data types and indexes in MySQL include: 1) Selecting the appropriate string type, such as CHAR for fixed length, VARCHAR for variable length, and TEXT for large text; 2) Be cautious in indexing, avoid over-indexing, and create indexes for common queries; 3) Use prefix indexes and full-text indexes to optimize long string searches; 4) Regularly monitor and optimize indexes to keep indexes small and efficient. Through these methods, we can balance read and write performance and improve database efficiency.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.