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

Post 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.. :?
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post 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.
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post 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..
ryanlwh
Forum Commoner
Posts: 84
Joined: Wed Sep 14, 2005 1:29 pm

Post 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.
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post 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...
ryanlwh
Forum Commoner
Posts: 84
Joined: Wed Sep 14, 2005 1:29 pm

Post 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?
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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? :)
ryanlwh
Forum Commoner
Posts: 84
Joined: Wed Sep 14, 2005 1:29 pm

Post 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.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

That wouldn't create a variable variable, it will just create a variable called '$$varname' :)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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>";
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post 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
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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?
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

it's within neither..my thread is improperly titled..musta been sleepy at the time..
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
Post Reply