PHP doesn't allow me to manage forms

This is a discussion on PHP doesn't allow me to manage forms within the PHP Language forums, part of the PHP Programming Forums category; I have installed PHP a number of times following tutorials from online and from a book. I have been able ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-06-2006
Village
 
Posts: n/a
Default PHP doesn't allow me to manage forms

I have installed PHP a number of times following tutorials from online
and from a book. I have been able to process simple functions such at
date() but when it comes to simply sending information from a HTML form
to a PHP page to display it doesn't work.

I know it isn't my programming as i have copied it word for word from a
book, and even used one of their examples from the site.

The code I have used in the PHP page is:

<?php
/* This page receives and handles the data generated by "form.htm".*/
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";
?>

and all of those variables relate to a text field in the form on the
HTML page (form.htm).

Any suggestions on how to sort this out?

Thank you very much

Reply With Quote
  #2 (permalink)  
Old 01-06-2006
Erwin Moller
 
Posts: n/a
Default Re: PHP doesn't allow me to manage forms

Village wrote:

> I have installed PHP a number of times following tutorials from online
> and from a book. I have been able to process simple functions such at
> date() but when it comes to simply sending information from a HTML form
> to a PHP page to display it doesn't work.
>
> I know it isn't my programming as i have copied it word for word from a
> book, and even used one of their examples from the site.
>
> The code I have used in the PHP page is:
>
> <?php
> /* This page receives and handles the data generated by "form.htm".*/
> 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";
> ?>
>
> and all of those variables relate to a text field in the form on the
> HTML page (form.htm).
>
> Any suggestions on how to sort this out?
>
> Thank you very much


Hi,

Well, you didn't show us all your code, so it is hard to say what went
wrong.

Try this:
send.html

***************************************
<html>
<body>
<form action="receive.php" method="Post">
firstname:<input type="text" name="firstname">
<br>
LastName<input type="text" name="LastName">
<br>
email:<input type="text" name="email">
<br>
Comments:<input type="text" name="Comments">
<br>
<input type="submit" value="Post me please">
</form>
</body>
</html>

***************************************

and the file receive.php:

***************************************
<?
$firstname=$_POST["firstname"];
$LastName=$_POST["LastName"];
$email=$_POST["email"];
$Comments=$_POST["Comments"];
?>
<html>
<body>
I received:
<br>
Firstname: <? echo $firstname; ?><br>
LastName: <? echo $LastName; ?><br>
email: <? echo $email; ?><br>
Comments: <? echo $Comments; ?><br>
</body>
</html>

***************************************


That code should always work.

Regards,
Erwin Moller
Reply With Quote
  #3 (permalink)  
Old 01-06-2006
Peter Fox
 
Posts: n/a
Default Re: PHP doesn't allow me to manage forms

Following on from Village's message. . .
>I have installed PHP a number of times following tutorials from online
>and from a book. I have been able to process simple functions such at
>date() but when it comes to simply sending information from a HTML form
>to a PHP page to display it doesn't work.
>
>I know it isn't my programming as i have copied it word for word from a
>book, and even used one of their examples from the site.

The book was taking some deprecated shortcuts.
(See 'register globals' in the manual)

try
print_r($_POST);
or
print_r($_REQUEST);
to see what has been passed to PHP, then you can pick the bits you want
out of the array, *validate them*, *validate them again* then use them.

--
PETER FOX Not the same since the bolt company screwed up
peterfox@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>
Reply With Quote
  #4 (permalink)  
Old 01-06-2006
Village
 
Posts: n/a
Default Re: PHP doesn't allow me to manage forms

Brilliant, that works fine. Thanks. I will look up about the Register
Globals thing to see what it is.

Reply With Quote
  #5 (permalink)  
Old 01-06-2006
Darkstar 3D
 
Posts: n/a
Default Re: PHP doesn't allow me to manage forms

Sounds to me like that book sucks. Especially if it didn't discuss
register globals before taking the short way out.

Reply With Quote
  #6 (permalink)  
Old 01-06-2006
Tim Van Wassenhove
 
Posts: n/a
Default Re: PHP doesn't allow me to manage forms

On 2006-01-06, Erwin Moller <since_humans_read_this_I_am_spammed_too_much@spam yourself.com> wrote:
> $firstname=$_POST["firstname"];
> $LastName=$_POST["LastName"];
> $email=$_POST["email"];
> $Comments=$_POST["Comments"];


I've got the feeling that tutorials should spend more attention to cleaning
input and output so the student can't shoot himself in the foot.

$html = array();
$html['firstname'] = htmlentities($_POST['firstname'], 'UTF-8');
....


echo "Your firstname is: {$html['firstname']} <br/>";
...


--
Met vriendelijke groeten,
Tim Van Wassenhove <http://timvw.madoka.be>
Reply With Quote
  #7 (permalink)  
Old 01-06-2006
Erwin Moller
 
Posts: n/a
Default Re: PHP doesn't allow me to manage forms

Tim Van Wassenhove wrote:

> On 2006-01-06, Erwin Moller
> <since_humans_read_this_I_am_spammed_too_much@spam yourself.com> wrote:
>> $firstname=$_POST["firstname"];
>> $LastName=$_POST["LastName"];
>> $email=$_POST["email"];
>> $Comments=$_POST["Comments"];

>
> I've got the feeling that tutorials should spend more attention to
> cleaning input and output so the student can't shoot himself in the foot.
>
> $html = array();
> $html['firstname'] = htmlentities($_POST['firstname'], 'UTF-8');
> ...
>
>
> echo "Your firstname is: {$html['firstname']} <br/>";
> ..
>
>


Hi/hoi Tim,

I agree with that.
I know I had my fair share of 'obscure bugs' when I started with PHP, and I
guess 90% had to do with characters: encoding/in-out database/show them in
html, show them in a textfield of a form, etc. etc.
You know what I am talking about. :P

'obscure bugs' in a ironic way because it was of course me who scewed up by
not paying attention to them from the start.
They are excactly the kind of things that make a habit of returning later in
the project, and always in a worse form, and of course close to deadline.
;-)

But I didn't want to confuse the OP with that because he clearly had
problems with the concept of forms and superglobals $_POST and $_GET.

btw, I didn't know that UTF-8 directive for htmlentities.
Now I do. :-)

Regards,
Erwin Moller
Reply With Quote
  #8 (permalink)  
Old 01-07-2006
Michael Trausch
 
Posts: n/a
Default Re: PHP doesn't allow me to manage forms

Village wrote:
>
> Brilliant, that works fine. Thanks. I will look up about the Register
> Globals thing to see what it is.
>


A good bit of advice: Don't use, nor rely on, register globals. That
functionality is going away in the future, according to the PHP web
site, I think it's slated for removal entirely in PHP 6.

Use the Superglobals instead. Some of the common ones are $_GET,
$_POST, and $_COOKIE. There are others, also. It's definitely
preferable to use them, however, because with register globals (just as
an example), let's say you have a POST form with a hidden value UID and
the user wanted to attempt to override it with a GET request appending
UID to the URL. The opposite could also be true, but not as likely.
The idea is that by using the superglobals, everything is separated into
different places, and it makes life somewhat more secure, easier, and
more intuitive to deal with.

You should get a book on PHP 5. :)

Later,
Mike
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 11:45 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0