Problem checking isset on multiple variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
someguyhere
Forum Contributor
Posts: 181
Joined: Sun Jul 27, 2008 3:24 pm

Problem checking isset on multiple variables

Post by someguyhere »

Can anyone tell me doing wrong here?

Code: Select all

if ( isset ( $_POST['length'] && $_POST['width'] && $_POST['height'] ) ) {
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Problem checking isset on multiple variables

Post by Celauran »

priyankagound
Forum Commoner
Posts: 27
Joined: Thu Sep 19, 2013 2:53 am

Re: Problem checking isset on multiple variables

Post 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)) {
/.....
}
someguyhere
Forum Contributor
Posts: 181
Joined: Sun Jul 27, 2008 3:24 pm

Re: Problem checking isset on multiple variables

Post by someguyhere »

Right; I need them all to be set. I will try if (isset($length, $width, $height)) {

Thanks guys!
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Problem checking isset on multiple variables

Post 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.
someguyhere
Forum Contributor
Posts: 181
Joined: Sun Jul 27, 2008 3:24 pm

Re: Problem checking isset on multiple variables

Post by someguyhere »

I am. Should I set them in an array instead?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Problem checking isset on multiple variables

Post 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'] ) ) {
Post Reply