Fixed(read the last post.you'll laugh, I know it:) )
Moderator: General Moderators
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
this is what happens when I vardump Fname.. I imagine all the others will return the same thing..
not too sure what that means..
Code: Select all
string(6) "-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
what do you see when you view source on the input field?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...
Try this:
Also, I am guessing that is a typo with $$varname and that you also are not using the same name for both, right? 
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;
}
}
}I guess he's trying to use variable variables.Jenk wrote:Try this:
Also, I am guessing that is a typo with $$varname and that you also are not using the same name for both, right?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; } } }
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
You are incorrect sir!Jenk wrote:That wouldn't create a variable variable, it will just create a variable called '$$varname'
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>";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
Code: Select all
<td><input type="text" name="Fname" value="" />
</td>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") ?>">Code: Select all
<input type="text" name="Fname" value="<?php echo ("$Fname") ?>" />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;
}
}
}Jcart, thanks for the suggestion on improving the variable variable naming:-D
I stand corrected.Jcart wrote:You are incorrect sir!Jenk wrote:That wouldn't create a variable variable, it will just create a variable called '$$varname'
http://ca3.php.net/manual/en/language.v ... riable.php
can be shortened toCode: Select all
$varname="form_" .$key; $$varname="<font color='RED'>Please enter something here.</font>";
Code: Select all
${"form_" . $key} = "<font color='RED'>Please enter something here.</font>";
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
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm