Fixed(read the last post.you'll laugh, I know it:) )

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

Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Fixed(read the last post.you'll laugh, I know it:) )

Post by Charles256 »

Code: Select all

foreach ($_POST as $key=>$value)
	  {
	  	if ($key!='Register')
		{
			if ($value=='')
			{
			  $varname="form_" .$key;
			  $$varname="<font color='RED'>Please enter something here.</font>";
			  $Error=1;
			}
		}
	  }
That's the loop... here's the form that's posted, or at least the part that should coincide with $key!='Register'

Code: Select all

<input type="submit" name="Register" value="Register">
and on the other page when it determines when to display the form looks like...

Code: Select all

if ($Error==1 || !(isset($Error)))
	{
	include('form.php');
	}
Now obviously I submitted a blank form but the $Error=1 part didn't get executed because the form isn't displayed after it is submitted. any ideas?
Last edited by Charles256 on Tue Sep 20, 2005 8:47 pm, edited 2 times in total.
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

why? one of the keys passed from the form would be register wouldn't it?
<-- is appearantly confused..
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what was the field you left "blank" ?
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

I left every field blank. :-d Just submitted a blank form.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

are you sure they were in the $_POST array?
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Re: function problems continued

Post by Buddha443556 »

Charles256 wrote:

Code: Select all

if ($Error==1 || !(isset($Error)))
	{
	include('form.php');
	}
You should be getting a warning if $Error wasn't set. Got your error_reporting set to E_ALL?
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

Code: Select all

<form action="index.php?register=yes&process=yes" method="post">
that should put every field in the form in the post array,shouldn't it?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

try adding this to your script

Code: Select all

print_r($_POST);
after the form has been submitted
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

Code: Select all

Array ( [Fname] =>
[Lname] =>
[Suffix] =>
[day] => 1 [month] => 1 [year] => 1900 [Email] =>
[Address] =>
[City] =>
[State] => Alabama [Zip] =>
[Register] => Register )
that's the output. to me it seems the values are blank...which means my if should be triggered,right?

[edit] rather most of them are blank:-D [/edit]
ryanlwh
Forum Commoner
Posts: 84
Joined: Wed Sep 14, 2005 1:29 pm

Post by ryanlwh »

try if(!$value); They might be NULL, not blank.
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

it didn't work. I added

Code: Select all

echo $Error;
after the foreach loop and it echoed "0" so I'm sure that if isn't getting executed...
okay...this makes no sense.. I added the following code to my page..

Code: Select all

echo ("$key ='$value'");
in the foreach loop obviously and take a look at what it outputted...

Code: Select all

Fname ='
'Lname ='
'Suffix ='
'day ='1'month ='1'year ='1900'Email ='
'Address ='
'City ='
'State ='Alabama'Zip ='
'
which implies to me there is a break line in the form field but here is an example of how the form field looks

Code: Select all

<td><input type="text" name="Fname" value="<?php echo $Fname ?>" />
        </td>
so why the devil is it picking up a break line?
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

oddly enough if i take out the PHP statement it takes out the break..but why would a php statement cause a break? I think my server hates me.. 8O
ryanlwh
Forum Commoner
Posts: 84
Joined: Wed Sep 14, 2005 1:29 pm

Post by ryanlwh »

maybe $Fname in the form has a line-break already? Where did you get $Fname from?
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

i declared them above the foreach loop which is giving me a problem;-D

Code: Select all

$Fname=$_POST['Fname'];
	  $Lname=$_POST['Lname'];
	  $Suffix=$_POST['Suffix'];
	  $Day=$_POST['day'];
	  $Month=$_POST['month'];
	  $Year=$_POST['year'];
	  $Email=$_POST['Email'];
	  $Address=$_POST['Address'];
	  $City=$_POST['City'];
	  $State=$_POST['State'];
	  $Zip=$_POST['Zip'];
	  $Error=0;
I also declared error=0 because if later on none of the errors are triggered i need to know when to process the form, ya know?:-D as you can see $Fname is just what's posted in the form, so up until the form is submitted $Fname doesn't exist
ryanlwh
Forum Commoner
Posts: 84
Joined: Wed Sep 14, 2005 1:29 pm

Post by ryanlwh »

what i meant is this

Code: Select all

<input type="text" name="Fname" value="<?php echo $Fname ?>" />
so this Fname is also initialized with the $_POST global array?
Post Reply