php - Check if $_GET is available and has specific value?

86

I'm trying to check to see if a $_GET value is available AND equal to 1 but the error is that the index is not defined.

<?php if ((isset($_GET['success'])) ||  ($_GET['success'] == 1)) { ?>
Do Something
<?php } ?>

Why is this a problem? I'm checking to see if it exists and then if it equals one and if so , do something.

Is there a better way to achieve this goal?

326

Answer

Solution:

Change the || (OR) to && (AND)

if ((isset($_GET['success'])) &&  ($_GET['success'] == 1))
300

Answer

Solution:

do this<?php if (isset($_GET['success']) { if($_GET['success']==1){} ?>

Do Something

<?php } ?>

772

Answer

Solution:

You need to change the OR for an AND in the conditional (&&)

707

Answer

Solution:

= OR

||&& = AND, which is what should have been used.

People are also looking for solutions to the problem: php - Laravel 5 named routes error

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.