Variable and field woes

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
mikebr
Forum Contributor
Posts: 243
Joined: Sat Sep 28, 2002 7:05 am

Variable and field woes

Post by mikebr »

I have a page that has a username field created using the following code:

Code: Select all

<input name="userName" value="<?php echo $userName; ?>" size=22 maxlength=40>
I have <?php extract($_POST); ?> at the top of this same page, now if I place some text in the field, say 'John' and I submit the form "action is back to itself" the field then has the value "<?php echo John; ?>", why would this be? I am testing locally "OSX". I set a couple of bits of text such as

Code: Select all

<?php
if ($un) &#123;
print "$un";
&#125; else &#123;
print "<font color=RED>$un</font>";
&#125;
?>
The $un value prints as expected so php seems must be getting parsed.

I haven't had this problem before so I am totally puzzeled on this.
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post by djot »

-
Hi,


Your input field is named userName.

Your testing part prints out $un, not $userName.

(show more code please)


djot
-
mikebr
Forum Contributor
Posts: 243
Joined: Sat Sep 28, 2002 7:05 am

Post by mikebr »

Your input field is named userName.

Your testing part prints out $un, not $userName.
That's right, I was only demonstrating that php is getting parsed, $un has nothing to do with the $userName variable.
(show more code please)
That's fairly much it apart from the html.

The form action is: (Just back to the same form that contains the $userName field)

Code: Select all

<form action="login.php" method=post name="theForm">

The full line that contains userName is:

Code: Select all

<p><input name="userName" value="<?php echo $userName; ?>" size=22 maxlength=40></p></td>
Thanks

Oh, and the form is called login.php
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it has the same data, because you asked php to print out $userName, which is what that field submits. I don't see how this is being misunderstood. :?
mikebr
Forum Contributor
Posts: 243
Joined: Sat Sep 28, 2002 7:05 am

Post by mikebr »

Humm... I removed the code and field then redid them again and now the <?php echo ; ?> does not appear, so that side seems to be sorted.

Unfortunately the variables do not seem to get passed on, or rather they do but.... I will explain:

I have added an include to the top of the login.php page;

Code: Select all

if(phpversion() >= "4.2.0") &#123;
	extract($_POST);
	extract($_GET);	
	
&#125;
echo "UN=$userName<br />PW = $userPassword<br />"; // E1
include ($path&#1111;'path_to_public_folder'] . $phpfolder&#1111;'phpfolder'] . "/inc.login.php");
echo "UN=$userName<br />PW = $userPassword<br />"; // E3
In this inc.login.php script I have placed the following:

Code: Select all

<?php
echo "UN=$userName<br />PW = $userPassword"; // E2
?>
Now the echos in E1 & E3 print out the values but E2 in the inc.login.php script shows these values as being empty (UN= PW= ), what gives here?, shurly the variable values in that script should be as they are set and not empty?

Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

sounds like you have some odd settings...
mikebr
Forum Contributor
Posts: 243
Joined: Sat Sep 28, 2002 7:05 am

Post by mikebr »

Yes, I guess so.

I loaded these files up to a server and checked them there and they seem to work on that server, so I thought the problem must be with my 'local' ini or config file but on checking another site I have locally that all seems to work, it is a functional database site with includes so if it works then I wonder why the new site does not.

Totally puzzeled
Post Reply