Home  >  Article  >  Database  >  Why Doesn't `if(isset($_POST['submit']))` Hide My Echoes and Table?

Why Doesn't `if(isset($_POST['submit']))` Hide My Echoes and Table?

Patricia Arquette
Patricia ArquetteOriginal
2024-11-07 15:25:03284browse

Why Doesn't `if(isset($_POST['submit']))` Hide My Echoes and Table?

Why if(isset($_POST['submit'])) is Not Hiding Echoes and Table

When using the if(isset($_POST['submit'])) condition, the goal is to display content only when the form's "Submit" button is clicked. However, in the provided code, the echoes and table appear when the script opens because the isset($_POST['submit']) condition is not evaluating to true.

The Root Cause

The issue lies in the submit button not having a name attribute. Without a name, the corresponding value from the POST array ($_POST['submit']) will be empty, causing the isset($_POST['submit']) condition to always evaluate to false.

The Fix

To resolve this issue, add a name attribute to the submit button:

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

With this change, the $_POST['submit'] value will be set when the button is clicked, allowing the isset($_POST['submit']) condition to work as expected. The echoes and table will now only appear after the button is clicked.

The above is the detailed content of Why Doesn't `if(isset($_POST['submit']))` Hide My Echoes and Table?. 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