What is if isset ($_ post submit )) in php?

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:

    



Exam Interface




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

Session ID:

Module Number:

Teacher Username:

Student Username:

Grade:

Order Results By:

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

"; echo "

Number of Records Shown in Result of the Search: $num

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

Any help will be much appreciated, Thank You.

Clive

36.9k8 gold badges86 silver badges111 bronze badges

asked Oct 15, 2011 at 3:07

BruceyBanditBruceyBandit

3,78219 gold badges59 silver badges128 bronze badges

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

answered Oct 15, 2011 at 3:12

1

What you're checking

if(isset($_POST['submit']))

but there's no variable name called "submit". well i want you to understand why it doesn't works. lets imagine if you give your submit button name delete and check if(isset($_POST['delete'])) then it works in this code you didn't give any name to submit button and checking its exist or not with isset(); function so php didn't find any variable like "submit" so its not working now try this :


answered Oct 15, 2011 at 8:03

What is if isset ($_ post submit )) in php?

Mohit BumbMohit Bumb

2,4252 gold badges32 silver badges52 bronze badges

0

You never named your submit button, so as far as the form is concerned it's just an action.

Either:

  1. Name the submit button ()
  2. Test if (!empty($_POST)) instead to detect when data has been posted.

Remember that keys in the $_POST superglobal only appear for named input elements. So, unless the element has the name attribute, it won't come through to $_POST (or $_GET/$_REQUEST)

answered Oct 15, 2011 at 3:11

Brad ChristieBrad Christie

98.8k16 gold badges149 silver badges198 bronze badges

1

Whats wrong in this?


login.php

if(isset($_POST['submit']) && !empty($_POST['submit'])) {
  // if (!logged_in()) 
  echo 'asodj';
}

Jeff Miller

2,3451 gold badge26 silver badges40 bronze badges

answered Mar 15, 2017 at 18:18

You must give a name to your submit button


Then you can call the button with $_POST['login']

What is if isset ($_ post submit )) in php?

Aleksandr M

24k12 gold badges68 silver badges136 bronze badges

answered Mar 16, 2015 at 10:51

What is if isset ($_ post submit )) in php?

The $_post function need the name value like:


Call

$var = strip_tags($_POST['example']);
if (isset($var)){
    // your code here
}

What is if isset ($_ post submit )) in php?

Laurel

5,88313 gold badges29 silver badges55 bronze badges

answered Sep 27, 2016 at 22:03

What is if isset ($_ post submit )) in php?

Another option is to use

$_SERVER['REQUEST_METHOD'] == 'POST'

answered Oct 19, 2018 at 22:21

1

If (isset($_POST[submit]) ,any time try this function it displays error code (do not access super global $_POST array directly)

answered Aug 4, 2021 at 19:50

You can use :

"

Or if you will to us buttons

In your php script if(isset($_POST['submit']))

The most important is the "name" attribute to perform the submission of the form

answered Apr 21 at 12:01

What is if isset ($_ post submit )) in php?

What is isset ($_ POST in PHP?

The isset() function checks whether a variable is set, which means that it has to be declared and is not NULL. This function returns true if the variable exists and is not NULL, otherwise it returns false.

What does Isset POST do?

Using “isset” You can use the “isset” function on any variable to determine if it has been set or not. You can use this function on the $_POST array to determine if the variable was posted or not. This is often applied to the submit button value, but can be applied to any variable.

Does isset () function do in PHP?

The isset function in PHP is used to determine whether a variable is set or not. A variable is considered as a set variable if it has a value other than NULL. In other words, you can also say that the isset function is used to determine whether you have used a variable in your code or not before.

How do you check if a submit button is clicked in PHP?

PHP isset() function is used to check if a variable has been set or not. This can be useful to check the submit button is clicked or not. The isset() function will return true or false value. The isset() function returns true if variable is set and not null.