[SOLVED] Am I overlooking the obvious?

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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

[SOLVED] Am I overlooking the obvious?

Post by John Cartwright »

Code: Select all

<?php
		if (!empty($_POST["Submit"]))
		{
			$fields   = array($_POST["lastname"],$_POST["email"],$_POST["email2"]);
						
			foreach ($fields as $field)
			{
echo $field;			
	if (!empty($field))
				{
					$fnum += 1;					
				}
				else
				{
					$fielderror[] = "You are missing". $field;
				}
			}
?>
For some reasons $field will never get printed. !?
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Is $_POST["Submit"] set/not empty?
What does a var_dump($_POST); show?
Sure it's not 'submit' instead of 'Submit'?
:o
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

oh no the rest is working perfectly...

when i output the array $fielderror[] its:

you are missing
you are missing
you are missing
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Ah, that's your logic...take another look at it:

Code: Select all

if (!empty($field))
{
    $fnum += 1;               
}
else
{
    $fielderror[] = "You are missing". $field;
}
So you're saying if $field is NOT empty then do $fnum += 1; .. otherwise, if it IS empty then add the message to the array :p
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

rofl @ me... its 4:46 in the morning.. sorry.
User avatar
fresh
Forum Contributor
Posts: 259
Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika

Post by fresh »

that's not an exscuse, ... ok it is :)
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

Am I overlooking the obvious?
Yes ;)
Post Reply