Page 1 of 1

Variables.

Posted: Fri May 30, 2003 11:41 am
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

Posted: Fri May 30, 2003 11:51 am
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";}
?>

Posted: Fri May 30, 2003 12:38 pm
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

Posted: Fri May 30, 2003 12:43 pm
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

Posted: Fri May 30, 2003 1:14 pm
by codders
Thanks everyone..... wee hee it worked now to get my head round mysql :)