Page 1 of 1
Problem checking isset on multiple variables
Posted: Tue Sep 10, 2013 9:16 am
by someguyhere
Can anyone tell me doing wrong here?
Code: Select all
if ( isset ( $_POST['length'] && $_POST['width'] && $_POST['height'] ) ) {
Re: Problem checking isset on multiple variables
Posted: Tue Sep 10, 2013 9:49 am
by Celauran
Re: Problem checking isset on multiple variables
Posted: Fri Sep 20, 2013 5:09 am
by priyankagound
If multiple parameters are supplied then isset() will return TRUE only if all of the parameters are set.
if (isset($length, $width, $height)) {
/.....
}
Re: Problem checking isset on multiple variables
Posted: Fri Sep 20, 2013 2:44 pm
by someguyhere
Right; I need them all to be set. I will try if (isset($length, $width, $height)) {
Thanks guys!
Re: Problem checking isset on multiple variables
Posted: Fri Sep 20, 2013 2:47 pm
by requinix
As long as you're not doing
Code: Select all
$length = $_POST['length'];
$width = $_POST['width'];
$height = $_POST['height'];
if (isset($length, $width, $height)) {
because that won't help with the "undefined offset" warnings should those things not be present.
Re: Problem checking isset on multiple variables
Posted: Fri Sep 20, 2013 3:23 pm
by someguyhere
I am. Should I set them in an array instead?
Re: Problem checking isset on multiple variables
Posted: Fri Sep 20, 2013 3:44 pm
by requinix
No arrays either. Deal with $_POST directly like you were doing before: take your original code and put commas in for the &&s.
Code: Select all
if ( isset ( $_POST['length'], $_POST['width'], $_POST['height'] ) ) {