Professional Web Applications Themes

Training Help - PHP Development

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

  1. #1

    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
    Ryan Stagg Guest

  2. #2

    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
    Jon Haworth Guest

  3. #3

    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" <jonlaughing-buddha.net> wrote in message
    news:008101c37920$944cee90$050a0a0aeris...
    > 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
    Ryan Stagg Guest

  4. #4

    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
    Jon Haworth Guest

Similar Threads

  1. CF Administrator training
    By gesiferd in forum Coldfusion Server Administration
    Replies: 0
    Last Post: March 21st, 02:02 PM
  2. Training Application Dev Help
    By Tom Muschetti in forum Dreamweaver AppDev
    Replies: 0
    Last Post: April 8th, 04:10 AM
  3. FS: Flash MX CD Training
    By minstrel in forum Macromedia Flash
    Replies: 0
    Last Post: September 1st, 02:03 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139