Page 1 of 1

Problem with global variables maybe?

Posted: Fri Feb 29, 2008 5:09 am
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.

Re: Problem with global variables maybe?

Posted: Fri Feb 29, 2008 9:22 am
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;
?>

Re: Problem with global variables maybe?

Posted: Tue Mar 04, 2008 7:02 am
by dna
10x a lot :) it worked :)

Re: Problem with global variables maybe?

Posted: Tue Mar 04, 2008 11:24 am
by RobertGonzalez
Moved to PHP - Code. Also added code tags to original post and the tags note.