Jump to content

Archived

This topic is now archived and is closed to further replies.

mick_otoole

Stupid Noobie question about form variables

Recommended Posts

'm trying to teach myself PHP and I've been working form a numer of different books. THe problem I'm having is when I pass form variables from one page to another they do not appear.
A very simple example is when I try to pass values from this page (orderform.html)

[code]<HTML>
<form action="processorder.php" method=post>
<table border=0>
<tr bgcolor=#cccccc>
<td width=150>Item</td>
<td width=15>Quantity</td>
</tr>
<tr>
<td>Tires</td>
<td align=center><input type=”text” name=”tireqty” size=3 maxlength=3></td>
</tr>
<tr>
<td>Oil</td>
<td align=center><input type=”text” name=”oilqty” size=3 maxlength=3></td>
</tr>
<tr>
<td>Spark Plugs</td>
<td align=center><input type=”text” name=”sparkqty” size=3 maxlength=3></td>
</tr>
<tr>
<td colspan=2 align=center><input type=submit value=”Submit Order”></td>
</tr>
</table>
</form>
</HTML>[/code]

i.e. The Values tireqty, oilqty and sparkqty to the following page (processorder.php)

[code]<html>
<head>
<title>Bob’s Auto Parts - Order Results</title>
</head>
<body>
<h1>Bob’s Auto Parts</h1>
<h2>Order Results</h2>
<?php
echo ("Order Processed on :");
echo date(" jS F, H:i");
echo "<br>";
echo "<p>Your order is as follows:";
echo "<br>";
echo $tireqty." tires<br>";
echo $oilqty." bottles of oil<br>";
echo $sparkqty." spark plugs<br>";
?>
</body>
</html>[/code]

THe values that I type in do not show up. The only thing that appears on the page is the descriptions.

I know that there is probably a very very simple solution for this I just can't seem to find it!

Oh yeah and before you ask I have installed Apache and PHP on my local machine!!!

Share this post


Link to post
Share on other sites
you need to call the vars using the method
in this case POST

so
$tireqty = $_POST["tireqty"];

Share this post


Link to post
Share on other sites
[code]<html>
<head>
<title>Bob’s Auto Parts - Order Results</title>
</head>
<body>
<h1>Bob’s Auto Parts</h1>
<h2>Order Results</h2>
<?php
echo ("Order Processed on :");
echo date(" jS F, H:i");
echo "<br>";
echo "<p>Your order is as follows:";
echo "<br>";
echo $_POST['tireqty']." tires<br>";
echo $_POST['oilqty']." bottles of oil<br>";
echo $_POST['sparkqty']." spark plugs<br>";
?>
</body>
</html>[/code]

That will do the job, Basicaly the way you coded it you would have to have globals turned on in your PHP.ini file so best way is to just use as above.

Regards
Liam

Share this post


Link to post
Share on other sites
just check the register_globals value in php.ini
or u can simply call this function at the begining of the file.
extract($_REQUEST);
or
U can just access the elements using $_GET,$_POST or $_REQUEST

Share this post


Link to post
Share on other sites
As I said earlier I'm a complete beginner so excuse the stupid questions in advance ...

Are you saying that I have to put the [code]$tireqty = $_POST["tireqty"];[/code] in the orderform.html or the processorder.php file?

Once again please excuse the ignorance!

Share this post


Link to post
Share on other sites
The thing I think about using $_REQUEST is if you using a POST method, cant someone inject using the GET method, and as your using REQUEST, that can be used instead

Share this post


Link to post
Share on other sites
shocker-z done it for you
to call a variable that has been posted using the POST method you use $_POST["
to call a variable that has been posted using the GET method, use $_GET["

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.