Ben
Ben

Reputation: 369

PHP empty() not working for me

I have a URL like: https://website.org/withdraw.php?valid_addr=1333mwKE7EcwLaR9ztdtEt7pPEfafpW4nn&amount=0.0002&_unique=1

and A line of code that reads:

if (empty($_GET['amount']) || empty($_GET['valid_addr']) || empty($_GET['_unique']))==0) exit();

If I remove the line then the code runs successfully. Can anyone tell me what I've done wrong.

The line is supposed to stop the code from running if any of the three fields are left empty.

Thanks.

Upvotes: 0

Views: 153

Answers (6)

5352580
5352580

Reputation: 101

if (($_GET['amount'] == 0) OR ($_GET['valid_addr'] == 0) OR ($_GET['_unique'] == 0)) { exit(); }

Upvotes: 1

Omkar
Omkar

Reputation: 308

Above your code has syntax error. I think you want to validate unique with 0 and 1. So you should have to try this code

if (empty($_GET['amount']) || empty($_GET['valid_addr']) || $_GET['_unique'])==0) exit();

Upvotes: 0

Makudex
Makudex

Reputation: 1082

You're code should be something like this:

if (empty($_GET['amount']) || empty($_GET['valid_addr']) || empty($_GET['_unique']))
{
  exit();
}

Upvotes: 0

hellcode
hellcode

Reputation: 2698

Syntax Error. Remove the ==0) part:

if(empty($_GET['amount']) || empty($_GET['valid_addr']) || empty($_GET['_unique'])) {
    exit();
}

Upvotes: 0

CollinD
CollinD

Reputation: 7573

I think you want to utilize array_key_exists rather than empty.

if (!array_key_exists('amount', $_GET) || 
    !array_key_exists('valid_addr', $_GET) ||
    !array_key_exists('_unique', $_GET))
    exit();

From PHP empty() docs

Determine whether a variable is considered to be empty. A variable is considered empty if it does not exist or if its value equals FALSE. empty() does not generate a warning if the variable does not exist.

See Array Key Exists docs

Upvotes: 2

Vignesh Bala
Vignesh Bala

Reputation: 919

Left parenthesis missing,

   if ((empty($_GET['amount']) || empty($_GET['valid_addr']) || empty($_GET['_unique']))==0) exit();

Try it...

Upvotes: 0

Related Questions