Problem with global variables maybe?

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
dna
Forum Newbie
Posts: 2
Joined: Fri Feb 29, 2008 5:00 am

Problem with global variables maybe?

Post by dna »

Everah | Please use [php], [code=text] and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


Hi,
I do not know is this the right place to post this topic, but i've got one problem. Here it is:
I got FreeBSD with apache22 and php installed and I've written one of the simpiest html file and one php file here is a part of them:
test.html:

Code: Select all

<form method=post action="test1.php">
<input type=text name="username">
<input type=submit>
</form>

test1.php:

Code: Select all

<?php
echo $username;
?>
The thing is that when I run the html file and click ot the submit button, it redirects me to test1.php but the "$username" variable do not appear. Has anyone tell me what may be wrong
Thank you in advance
Julian


Everah | Please use [php], [code] and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.
Last edited by RobertGonzalez on Tue Mar 04, 2008 11:24 am, edited 3 times in total.
Reason: Added the tags note and code tags around untagged code blocks
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Problem with global variables maybe?

Post by Jonah Bron »

You have not defined the $username variable. It is inside the $_POST super-global array. This is what you would want:

Code: Select all

<?php
echo $_POST['username'];
?>
or

Code: Select all

<?php
$username = $_POST['username'];
echo $username;
?>
dna
Forum Newbie
Posts: 2
Joined: Fri Feb 29, 2008 5:00 am

Re: Problem with global variables maybe?

Post by dna »

10x a lot :) it worked :)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Problem with global variables maybe?

Post by RobertGonzalez »

Moved to PHP - Code. Also added code tags to original post and the tags note.
Post Reply