Variables.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
codders
Forum Newbie
Posts: 3
Joined: Fri May 30, 2003 11:41 am
Location: Essex UK

Variables.

Post by codders »

Hello, I am just trying to learn PHP and have started at the beginning... I hope :)

andyway... I have installed Apache 1.3.27 and PHP 4.2.3 and all seems to be ok. But like I said I am starting at the beginning with this.....

I have created a HTML form including the following.....

<form action="HandleForm.php" method="post">
First Name <input type=text name="first_name" size="20"><br>

and the HandleForm.php file with this in......

<?php
/* this page receives and handles the data generated by "form.html". */
print "this is your $first_name<br>\n";
?>

While it prints the "this is your " it don't pass the variable to it.... Help please to a newbie.

Regards

Codders
penguinboy
Forum Contributor
Posts: 171
Joined: Thu Nov 07, 2002 11:25 am

Post by penguinboy »

try

Code: Select all

<?php
print "this is your ".$_POST[first_name]."<br>\n";
?>
vars from forms get passed in the $_POST array
vars in the url get passed in the $_GET array


so if you had something like


<form action="HandleForm.php?P=Y" method="post">


you could do:

Code: Select all

<?php
/* this page receives and handles the data generated by "form.html". */ 
if($_GET[P]=="Y"){print "this is your ".$_POST[first_name]."<br>\n";}
?>
codders
Forum Newbie
Posts: 3
Joined: Fri May 30, 2003 11:41 am
Location: Essex UK

Post by codders »

Thanks..... I'll give it a go.

The ironic thing is that I am using a book to learn PHP, and I cant get the script to work... hahaha
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Just a small note - all array elements should be quoted:
Array do's and don'ts

For information on passing values from forms:
Before Post Read: Concerning Passing Variables in PHP 4.2+

Many of the books are based on older versions of PHP and thus don't take into account changes that have been made to the default installation in the last year or so.

Mac
codders
Forum Newbie
Posts: 3
Joined: Fri May 30, 2003 11:41 am
Location: Essex UK

Post by codders »

Thanks everyone..... wee hee it worked now to get my head round mysql :)
Post Reply