PDA

View Full Version : Test for isset and value?


mjones74
12-05-2006, 03:46 AM
Hi, is there a reason to check for a post-var being set AND containing a value, rather than just checking the value?

if (isset($_POST['submit']) && ($_POST['submit'] == 'Submit Order')) {
...
}

vs.

if ($_POST['submit'] == 'Submit Order') {
...
}

Thanks. :)

felgall
12-05-2006, 05:23 AM
If you test for a field containing a specific value and the field doesn't exist then you will get an error. The field must exist in order to be able to test what value it contains. Since post variables depend on being defined in a form on the previous page in order for them to exist it is good coding practice to allow for the prior page not defining a specific field to pass to your script so that you control what happens in that situation.

mjones74
12-07-2006, 10:44 PM
Thanks Steven! :thumbsup: