Jump to content


Photo

Stupid Noobie question about form variables


  • Please log in to reply
6 replies to this topic

#1 mick_otoole

mick_otoole
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 09 August 2006 - 11:29 AM

'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)

<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>

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

<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>

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!!!

#2 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 09 August 2006 - 11:30 AM

you need to call the vars using the method
in this case POST

so
$tireqty = $_POST["tireqty"];
Tell me the problem, I will try tell you the solution

#3 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 09 August 2006 - 11:33 AM

<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>

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
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#4 manmadareddy

manmadareddy
  • Members
  • PipPipPip
  • Advanced Member
  • 50 posts

Posted 09 August 2006 - 11:34 AM

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


#5 mick_otoole

mick_otoole
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 09 August 2006 - 11:36 AM

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
$tireqty = $_POST["tireqty"];
in the orderform.html or the processorder.php file?

Once again please excuse the ignorance!

#6 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 09 August 2006 - 11:36 AM

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
Tell me the problem, I will try tell you the solution

#7 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 09 August 2006 - 11:37 AM

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["
Tell me the problem, I will try tell you the solution




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users