can't collect data from form

Problems with the Windows version of XAMPP, questions, comments, and anything related.

can't collect data from form

Postby cooldays » 14. September 2008 14:22

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?
new to php programming
cooldays
 
Posts: 2
Joined: 14. September 2008 14:11

Postby Wiedmann » 14. September 2008 14:25

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...
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

ATTN:WIEDMANN

Postby cooldays » 14. September 2008 14:49

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;

?>
new to php programming
cooldays
 
Posts: 2
Joined: 14. September 2008 14:11

Postby da233 » 14. September 2008 15:21

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.
da233
 
Posts: 8
Joined: 13. September 2008 03:57

Re: ATTN:WIEDMANN

Postby Nobbie » 14. September 2008 15:47

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
Nobbie
 
Posts: 13170
Joined: 09. March 2008 13:04


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 92 guests