RainbowdashTM
RainbowdashTM

Reputation: 21

How to tell if a post is posted, or just empty

Is it possible to tell whether the Post is just Empty, or Just hasn't been posted yet? I know

if($_POST['varible']!="") {
    $loginerr="";
} else  {
    $loginerr="Please check your entry.";
}

or

if(ifempty($_POST['varible']) {
    $loginerr="Please Check your Entry.";
} else {
    $loginerr="";
}

I just want a way, to tell whether the $_POST has been sent or not.

Upvotes: 1

Views: 80

Answers (6)

Dinesh
Dinesh

Reputation: 4110

<?php
//save it in a variable
$variable = $_POST['variable'];
//now check
if(empty($variable )) {

echo "The field was empty";

}
else
{
//whatever you want
}
?>

Upvotes: 0

Sibiraj PR
Sibiraj PR

Reputation: 1481

PHP isset is used for checking the row exist in array. empty is used for checking the array value. So here we can use this two in if condition is better.

 if(isset($_POST['vaiable']) && !empty($_POST['vaiable'])){

 //Here all the condition is satisfied and the $_POST['vaiable'] definitely have some value

 }

Upvotes: 2

Jeevan
Jeevan

Reputation: 45

the syntax to check is

if(isset($_POST['vaiable'])){code goes here}

to check post is empty or not you can check by following syntax

If(empty($_POST['vaiable'])){code goes here}


if(!empty($_POST['varible'])) {
    $loginerr="";
} else  {
    $loginerr="Please check your entry.";
}

Upvotes: 1

david
david

Reputation: 3228

$loginErr='';
if (!isset($_POST['variable']))
    $loginerr="Please Check your Entry.";

Upvotes: 2

Lance
Lance

Reputation: 4820

Use the empty function in PHP

if(empty($_POST['varible'])) {
    $loginerr = "Please Check your Entry.";
 } else {
    $loginerr = "";
 }

OR the isset function

if(!isset($_POST['varible'])) {
    $loginerr = "Please Check your Entry.";
 } else {
    $loginerr = "";
 }

Upvotes: 0

Mani
Mani

Reputation: 888

Try this code

if(empty($_POST['varible']))
{
    $loginerr="Please Check your Entry.";
} 
else 
{
    $loginerr = "";
}

Upvotes: 0

Related Questions