Page 1 of 1

can't collect data from form

PostPosted: 14. September 2008 14:22
by cooldays
I am new to php programming. I want to collect data from a text box form and use it in my php code. whenever I hit on the submit button, the data is appended to the url but not displayed on the page containing my php code. Is there any environment variables that I have to set? can somebody help me out?

PostPosted: 14. September 2008 14:25
by Wiedmann
whenever I hit on the submit button, the data is appended to the url but not displayed on the page containing my php code.

Maybe there is something wrong with your PHP code...

ATTN:WIEDMANN

PostPosted: 14. September 2008 14:49
by cooldays
WIEDMANN,
You can examine the code urself, I believe there is nothing wrong with the code
T
This code is on the first page by name first.php

<html>
<form action="process.php" method=get>
Please type your name here
<input type=text name="username"><br>
<input type=submit value="submit data">

</form>
</html>

This code is on the second page by name second.php
I expect the username to be printed on this page but that isnt so, it is only appended to the url
<?php

print $username;

?>

PostPosted: 14. September 2008 15:21
by da233
When you use the GET method, all of the form information will be posted into the URL, which is perfectly fine if you want to do it that way. However, you need to grab those variables in order to get them to show up on your page.

My php is rusty so don't take me 100% on this, but instead of naming the other file "second.php", it has to be "process.php" since that is the page where all the form data is going to be sent to.

Re: ATTN:WIEDMANN

PostPosted: 14. September 2008 15:47
by Nobbie
cooldays wrote:<?php

print $username;

?>


This is very old style PHP Code and depends on the (deprecated!) setting of register_globals in php.ini.

Use $_GET Array for GET Request instead:

Code: Select all
<?php

print $_GET['username'];

?>


For more information about the superglobal Arrays $_GET, $_POST etc. read the documentation: http://www.php.net/manual/en/language.v ... ternal.php