473,473 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

Jan 6 '06 #1
7 1406
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
Jan 6 '06 #2
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
pe******@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>
Jan 6 '06 #3
Brilliant, that works fine. Thanks. I will look up about the Register
Globals thing to see what it is.

Jan 6 '06 #4
On 2006-01-06, Erwin Moller <si******************************************@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>
Jan 6 '06 #5
Tim Van Wassenhove wrote:
On 2006-01-06, Erwin Moller
<si******************************************@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
Jan 6 '06 #6
Sounds to me like that book sucks. Especially if it didn't discuss
register globals before taking the short way out.

Jan 7 '06 #7
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
Jan 7 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Tonya | last post by:
Hi, Does anyone have any example of how i can manage forms in my application?? I want to be able to reference my form instances that are currently open from other forms. why cant i open...
2
by: Olaf | last post by:
I have a frameset page witch contains the myFuc() function. The function is accessed from a page in one of the frames in the frameset. An example is shown below. <input...
4
by: Tonya | last post by:
Hi, Does anyone have any example of how i can manage forms in my application?? I want to be able to reference my form instances that are currently open from other forms. why cant i open...
35
by: mwelsh1118 | last post by:
Why doesn't C# allow incremental compilation like Java? Specifically, in Java I can compile single .java files in isolation. The resulting individual .class files can be grouped into .jar files....
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.