Bluehost.com Web Hosting $6.95

Training Help

This is a discussion on Training Help within the PHP General forums, part of the PHP Programming Forums category; I recently aquired a copy of the book PHP and Mysql web development by SAMS. I have begun reading through ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-12-2003
Ryan Stagg
 
Posts: n/a
Default Training Help

I recently aquired a copy of the book PHP and Mysql web development by SAMS.

I have begun reading through it and it seems to be a very usefull book
however I started doing the first exersise which is a simple HTML Processor,
the HTML page is as follows:

<html>
<head>
<title>Bob's Auto Parts - Order Results</title>
</head>
<body>
<h1>Bob's Auto Parts</h1>
<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>
</body>
</html>

And the processor PHP page is:

<html>
<head>
<title>Bob's Auto Parts - Order Results</title>
</head>
<body>
<h1>Bob's Auto Parts</h1>
<h2>Order Results</h2>
<?
echo "<p>Order Processed at ";
echo date("H:i, ");
echo "on ";
echo date ("jS F");
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>

I get an error???? this code is taken directly from the book.....

Bob's Auto Parts
Order Results
Order Processed at 21:08, on 12th September


Your order is as follows:

Notice: Undefined variable: tireqty in
c:\inetpub\wwwroot\php\processorder.php on line 16
tires

Notice: Undefined variable: oilqty in
c:\inetpub\wwwroot\php\processorder.php on line 17
bottles of oil

Notice: Undefined variable: sparkqty in
c:\inetpub\wwwroot\php\processorder.php on line 18
spark plugs


Help



Ryan
Reply With Quote
  #2 (permalink)  
Old 09-12-2003
Jon Haworth
 
Posts: n/a
Default Re: [PHP] Training Help

Hi Ryan,

Sounds like register_globals is turned off on your server (this is generally
a Good Thing). Rather than having all your form fields converted directly
into variables - which your book is assuming, as it's how PHP used to do
it - you'll need to access them via the $_POST array.

Try changing this line:

> echo $tireqty." tires<br>";


To this:

echo $_POST["tireqty"]. " tires<br>";

Search the manual or the list archives for "register_globals" and you'll get
loads of info about this.

Cheers
Jon
Reply With Quote
  #3 (permalink)  
Old 09-12-2003
Ryan Stagg
 
Posts: n/a
Default Re: [PHP] Training Help

Thanks mate, problem kinda fixed, looks like this now...

<html>
<head>
<title>Bob's Auto Parts - Order Results</title>
</head>
<body>
<h1>Bob's Auto Parts</h1>
<h2>Order Results</h2>
<?
$tireqty = $_POST['tireqty'];
$oilqty = $_POST['oilqty'];
$sparkqty = $_POST['sparkqty'];
echo "<p>Order Processed at ";
echo date("H:i, ");
echo "on ";
echo date ("jS F");
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>

Ryan


"Jon Haworth" <jon@laughing-buddha.net> wrote in message
news:008101c37920$944cee90$050a0a0a@eris...
> Hi Ryan,
>
> Sounds like register_globals is turned off on your server (this is

generally
> a Good Thing). Rather than having all your form fields converted directly
> into variables - which your book is assuming, as it's how PHP used to do
> it - you'll need to access them via the $_POST array.
>
> Try changing this line:
>
> > echo $tireqty." tires<br>";

>
> To this:
>
> echo $_POST["tireqty"]. " tires<br>";
>
> Search the manual or the list archives for "register_globals" and you'll

get
> loads of info about this.
>
> Cheers
> Jon

Reply With Quote
  #4 (permalink)  
Old 09-12-2003
Jon Haworth
 
Posts: n/a
Default Re: [PHP] Training Help

Hi Ryan,

> $tireqty = $_POST['tireqty'];
> $oilqty = $_POST['oilqty'];
> $sparkqty = $_POST['sparkqty'];


That'll certainly fix the problem, but it kind of defeats the point of using
$_POST :-)

Ideally you'd clean the data at this point to make sure no-one's trying to
submit anything nasty (Google on "SQL injection" for an idea of what can be
done).

Seeing as these are quantities, checking them via PHP's is_numeric()
function would probably be a good idea, and making sure they're inside
sensible ranges (between 0 and 50, say) might be worthwhile as well.

Cheers
Jon
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 02:15 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0