


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 "
Student Id | "; echo "Forename | "; echo "Session Id | "; echo "Grade | "; echo "Mark | "; echo "Module | "; echo "Teacher | "; echo "
---|---|---|---|---|---|---|
" . $row['StudentId'] . " | "; echo "" . $row['Forename'] . " | "; echo "" . $row['SessionId'] . " | "; echo "" . $row['Grade'] . " | "; echo "" . $row['Mark'] . " | "; echo "" . $row['ModuleName'] . " | "; echo "" . $row['TeacherId'] . " | "; echo "
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!

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

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

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

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

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.

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.

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

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.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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
Small size, syntax highlighting, does not support code prompt function

Dreamweaver CS6
Visual web development tools

Atom editor mac version download
The most popular open source editor

SublimeText3 Chinese version
Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.
