Jump to content
xisto Community
mrdee

More Advice Needed From Php Experts.

Recommended Posts

I am a novice, trying to learn PHP/MySQL.

I have began to copy a script from a tutorial site, and entered it on my local machine (localhost).
By the way, PHP, MySQL and Apache are all set up correctly and running.

However, the problem I have is with the script:

I am aware of the fact that in PHP, variables begin with a dollar sign.
The problem is, I have entered a HTML page with a web form on it, the input in the web form passes on variables to a PHP script.

Here is the code for "orderform.html":

<html><body><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" name="submit" value="Submit Order"></td></tr></table></form></body></html>

As you can see, the web form is supposed to pass on 3 variables to the PHP script "processorder.php", namely "tireqty", "oilqty" and "sparkqty".
(in PHP, that would then be "$tireqty", "$oilqty" and "$sparkqty").

And here is the code for the script "processorder.php":
>
<html><head><title>Bob´s Auto Parts - Order Results</title></head><body><h1>Bob´s Auto Parts</h1><h2>Order Results</h2><?phpecho "<p>Order processed at ";echo date("H:i, 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
.
However, when I run the orderform.html page and enter some values, after submitting, I get the following errors:

[b]Notice[/b]: Undefined variable: tireqty in [b]C:\phpscripts\practice\bobsparts\processorder.php[/b] on line [b]14[/b]tires[b]Notice[/b]: Undefined variable: oilqty in [b]C:\phpscripts\practice\bobsparts\processorder.php[/b] on line [b]15[/b]bottles of oil[b]Notice[/b]: Undefined variable: sparkqty in [b]C:\phpscripts\practice\bobsparts\processorder.php[/b] on line [b]17[/b]spark plugs

Now, I assume that is because in HTML, the values do not need to be preceded by a dollar sign, and PHP does not recognise them, then again, the variables exist and are passed on to the PHP script by the HTML page, so where is the fault?

If even people who write tutorials can't get their code right, how on earth are we supposed to learn?

Anyway, any advice will be very gratefully accepted.

Share this post


Link to post
Share on other sites

Hi!One of the problems with using PHP code from tutorials is that some of them are quite dated. The particular tutorial that you are using seems to have been about in the time when the default settings for PHP had the variables for the form 'registered'. As a quick fix, you can put this line into the top of your processorder.php file:"<?php extract($_FORM); ?>" (without the quotes)and check it out again.

Share this post


Link to post
Share on other sites

Thank you for your advice, k_nitin_r.
I put the line in, but I get even more errors now.

This is what the PHP script generated:

[b]Warning[/b]: extract() [[url="http://forums.xisto.com/no_longer_exists/;: First argument should be an array in [b]C:phpscriptspracticebobspartsprocessorder.php[/b] on line [b]9[/b]Order processed at 00:53, 23rd FebruaryYour order is as follows:[b]Notice[/b]: Undefined variable: tireqty in [b]C:phpscriptspracticebobspartsprocessorder.php[/b] on line [b]15[/b]tires[b]Notice[/b]: Undefined variable: oilqty in [b]C:phpscriptspracticebobspartsprocessorder.php[/b] on line [b]16[/b]bottles of oil[b]Notice[/b]: Undefined variable: sparkqty in [b]C:phpscriptspracticebobspartsprocessorder.php[/b] on line [b]18[/b]spark plugs

So, it looks like the code might be more outdated than you suspect.

Like I said, hardly a way to get us to learn, is it?

Share this post


Link to post
Share on other sites

Replace the $_FORM with a $_POST. My bad, I've been using so many different programming languages that I keep getting the names of the variables mixed up. Try it with $_POST and see if it gives you the result that you expect.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.