File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Simple PHP problem
Joined: Apr 11, 2005
Jul 16, 2010 16:35:47
Hi, I'm using the book...PHP for the world wide web
In chapter 3 there are two scripts, form.html and HandleForm.php shown below:
<HTML> <HEAD> <TITLE>HTML Form</TITLE> </HEAD> <BODY> <FORM ACTION="HandleForm.php" method="POST"> First Name <INPUT TYPE=TEXT NAME="FirstName" SIZE=20><BR> Last Name <INPUT TYPE=TEXT NAME="LastName" SIZE=40><BR> E-mail Address <INPUT TYPE=TEXT NAME="Email" SIZE=60><BR> Comments <TEXTAREA NAME="Comments" ROWS=5 COLS=40></TEXTAREA><BR> <INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Submit!"> </FORM> </BODY> </HTML>
<HTML> <HEAD> <TITLE>Form Results</TITLE> </HEAD> <BODY> <?php /* This page receives and handles the data generated by "form.html". */ print ("Your first name is $FirstName.<BR>\n"); print ("Your last name is $LastName.<BR>\n"); print ("Your E-mail address is $Email.<BR>\n"); print ("This is what you had to say:<BR>\n $Comments<BR>\n"); ?> </BODY> </HTML>
But when I run it and enter data, I get this..
Your first name is .
Your last name is .
Your E-mail address is .
This is what you had to say:
For some reason the $name is just blank.
My web hosting uses PHP5, and the book is for PHP 3 and 4, but I doubt thats why.
Can anyone help??
Joined: Jul 11, 2001
Jul 16, 2010 20:21:28
Either the book is wrong or you're missing a step. If you post a form in PHP, you have to get the values from the $_POST variable like so...
$_POST['FirstName'] $_POST['LastName'] $_POST['Email'] $_POST['Comments']
Not sure what they are doing in the code you've posted.
GenRocket - A Test Data Generation Platform
Joined: Apr 11, 2005
Jul 17, 2010 05:33:59
Thanks, yes thats right, apparently its a security thing new to PHP5.
So you use GET for get requests, and POST for post requests.
I hope my 2 php books aren't too outdated with regards to other bits of code.
Rafael Monteiro Dourado
Joined: Jul 29, 2010
Jul 29, 2010 08:52:43
guy this book is old, try another one like the "PHP 5 Power Programming" .
Joined: Apr 06, 2010
Jul 29, 2010 09:09:38
The feature is called "Register Globals". In old versions of PHP what you're doing was allowed by default, but in PHP 4.2 it was disabled by default for security reasons. And in PHP5 it's officially deprecated. Don't use it
I agree. Here's the link:
subject: Simple PHP problem
JavaBeans and Servlets
Simple examples of JSP
Problem with accessing servlet from browser
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014