Forum Moderators: coopster

Message Too Old, No Replies

just out off curiousity...

is ti possible with a while loop..?

         

kumarsena

3:35 pm on Oct 17, 2004 (gmt 0)

10+ Year Member



if (!isset($_POST['name']) ¦¦ empty($_POST['name']) ¦¦!isset($_POST['email']) ¦¦ empty($_POST['email']) ¦¦!isset($_POST['messege']) ¦¦ empty($_POST['messege']) )
{
echo 'Please fill in all fields';
exit();
}

else
{
//do something
}

was wondering if the above code, which chceks for set and empty fields, can be done with a while loop. or any opther way for that matter? above code works fine, but just like to know my options...

k

Cook

3:38 pm on Oct 17, 2004 (gmt 0)

10+ Year Member



Well there are always several ways of doing the same thing, but in this particular case, I think an if statement is just fine, and I can't think of a way a while loop would help.

Cheers,
Cook

mincklerstraat

3:44 pm on Oct 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Agree with Cook here if it's just this few - but if it's more (and later it will be, if not this script, than another script):

$errorflag = 0; 
$checkarray = array('name', 'email', 'message');
foreach($checkarray as $v){
if(empty($_POST[$v])) $errorflag = 1;
}
if($errorflag) {
echo 'Please fill in all fields';
} else {
/* do something else */
}

note: checking to see if $x is set and if it's empty is redundant. For this you can just check if it's empty.

kumarsena

3:57 pm on Oct 17, 2004 (gmt 0)

10+ Year Member



as usual...good advice..

tnx guys..

didnt think about just chceking for empty...

k

AjiNIMC

11:46 am on Oct 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To make this
(!isset($_POST['name']) ¦¦ empty($_POST['name']) ¦¦!isset($_POST['email']) ¦¦ empty($_POST['email']) ¦¦!isset($_POST['messege']) ¦¦ empty($_POST['messege']) )

a while look , first you need to make them variable second you need to use your brain like a mathematicians.

They Work hard
get the solution
calculate the complexity
(never think there is an alternative , never think is it needed , just prove thats possible)

AjiNIMC mathematician by mistake