Page 2 of 3

Posted: Tue Sep 20, 2005 2:19 pm
by Charles256
I don't see what you're getting at.. yes when the form is submitted a variable named $Fname is set equal to $_POST['Fname'] that way if errors occur I can put their First name back in the proper field, that way they don't have to start from scratch.. :?

Posted: Tue Sep 20, 2005 2:44 pm
by neophyte
When I'm working on these problems I like to use var_dump($var_to_test); to see what variables are set, and what kinda data is in them. Helps alot when trouble shooting. Also double check you form and variable names.

Posted: Tue Sep 20, 2005 2:52 pm
by Charles256
this is what happens when I vardump Fname.. I imagine all the others will return the same thing..

Code: Select all

string(6) "
not too sure what that means..

Posted: Tue Sep 20, 2005 3:04 pm
by ryanlwh
it means Fname is a string of length 6, with something that the browser would not display. you could view source and see what's really between the quotes.

you may want to look into how the form is created. there must be something inside the values of the input.

Posted: Tue Sep 20, 2005 3:11 pm
by Charles256
the source still showed string(6)....i don't see the point in that...why is the form putting a break in the input field which is then put in the variable? :: cries :: sooo frustrating...what I get for not hard coding a check 15 times over...

Posted: Tue Sep 20, 2005 3:30 pm
by ryanlwh
Charles256 wrote:the source still showed string(6)....i don't see the point in that...why is the form putting a break in the input field which is then put in the variable? :: cries :: sooo frustrating...what I get for not hard coding a check 15 times over...
what do you see when you view source on the input field?

Posted: Tue Sep 20, 2005 3:40 pm
by Jenk
Try this:

Code: Select all

foreach ($_POST as $key=>$value)
      {
          if ($key!='Register')
        {
            if (empty($value))
            {
              $varname="form_" .$key;
              $$varname="<font color='RED'>Please enter something here.</font>";
              $Error=1;
            }
        }
      }
Also, I am guessing that is a typo with $$varname and that you also are not using the same name for both, right? :)

Posted: Tue Sep 20, 2005 3:47 pm
by ryanlwh
Jenk wrote:Try this:

Code: Select all

foreach ($_POST as $key=>$value)
      {
          if ($key!='Register')
        {
            if (empty($value))
            {
              $varname="form_" .$key;
              $$varname="<font color='RED'>Please enter something here.</font>";
              $Error=1;
            }
        }
      }
Also, I am guessing that is a typo with $$varname and that you also are not using the same name for both, right? :)
I guess he's trying to use variable variables.

Posted: Tue Sep 20, 2005 3:58 pm
by Jenk
That wouldn't create a variable variable, it will just create a variable called '$$varname' :)

Posted: Tue Sep 20, 2005 4:10 pm
by John Cartwright
Jenk wrote:That wouldn't create a variable variable, it will just create a variable called '$$varname' :)
You are incorrect sir!
http://ca3.php.net/manual/en/language.v ... riable.php

Code: Select all

$varname="form_" .$key;
              $$varname="<font color='RED'>Please enter something here.</font>";
can be shortened to

Code: Select all

${"form_" . $key} = "<font color='RED'>Please enter something here.</font>";

Posted: Tue Sep 20, 2005 7:24 pm
by Charles256

Code: Select all

<td><input type="text" name="Fname" value="" />
        </td>
that's the source of the form for the Fname an dit's the same with the rest of them...
i've also had a theory but it seems too stupid to be true....when you have the error of an undefined variable hte first thing the code includes is a <br />...maybe since the variable in the value isn't defined on first run perhaps it's including hte break? but if that's the case why doesn't it do that on my other login page? makes no sense....
for example..on another page this produces an empty variable...

Code: Select all

<input type="text" name="username" value="<?php echo ("$username") ?>">
however this produces a variable with the valuable <br />

Code: Select all

<input type="text" name="Fname" value="<?php echo ("$Fname") ?>" />
even when i change the second one to resemble hte first one (semantic changes at best) it's still not registering the if statement... the foreach does loop the proper times and through the variables..they're just not empty..

Code: Select all

foreach ($_POST as $key=>$value)
	  {
	  	if ($key!='Register')
		{
			if (empty($value))
			{
			  ${"form_" . $key} = "<font color='RED'>Please enter something here.</font>";
			  $Error=1;
			}
		}
	  }
who knew such a simple loop could cause such heart ache? though i doub tit's the loops fault...
Jcart, thanks for the suggestion on improving the variable variable naming:-D

Posted: Tue Sep 20, 2005 8:23 pm
by Jenk
Jcart wrote:
Jenk wrote:That wouldn't create a variable variable, it will just create a variable called '$$varname' :)
You are incorrect sir!
http://ca3.php.net/manual/en/language.v ... riable.php

Code: Select all

$varname="form_" .$key;
              $$varname="<font color='RED'>Please enter something here.</font>";
can be shortened to

Code: Select all

${"form_" . $key} = "<font color='RED'>Please enter something here.</font>";
I stand corrected.

But why would you do that?

BTW, is that loop within a function or class?

Posted: Tue Sep 20, 2005 8:25 pm
by Charles256
it's within neither..my thread is improperly titled..musta been sleepy at the time..

Posted: Tue Sep 20, 2005 8:26 pm
by Charles256
and i do that because I need to make variables storing that error message and all the errors must be differently named so I can echo them back on the form, make sense?

Posted: Tue Sep 20, 2005 8:34 pm
by feyd
why not store them into an array? They are far more straight forward and finite than dynamic variables.... not to mention less of a security hole..