|
|
More Advice Needed From Php Experts. | ||
Discussion by mrdee with 3 Replies.
Last Update: April 24, 2012, 3:16 pm | |||
![]() |
|
|
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":
CODE
<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":
>
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 "<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:
CODE
Notice: Undefined variable: tireqty in C:\phpscripts\practice\bobsparts\processorder.php on line 14tires
Notice: Undefined variable: oilqty in C:\phpscripts\practice\bobsparts\processorder.php on line 15
bottles of oil
Notice: Undefined variable: sparkqty in C:\phpscripts\practice\bobsparts\processorder.php on line 17
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.
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.
I put the line in, but I get even more errors now.
This is what the PHP script generated:
CODE
Warning: extract() url="http://127.0.0.1/practice/bobsparts/function.extract"]function.extract[/url: First argument should be an array in C:\phpscripts\practice\bobsparts\processorder.php on line 9
Order processed at 00:53, 23rd February
Your order is as follows:
Notice: Undefined variable: tireqty in C:\phpscripts\practice\bobsparts\processorder.php on line 15
tires
Notice: Undefined variable: oilqty in C:\phpscripts\practice\bobsparts\processorder.php on line 16
bottles of oil
Notice: Undefined variable: sparkqty in C:\phpscripts\practice\bobsparts\processorder.php on line 18
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?
Similar Topics:
Php In Five Minutes
What Is Php Description
Php Upload Files To Secure Director...
A Question About The Php Mail() Function (12)
|
(0) Php Register Form Validation Help
|
Loading...
HOME 





Google I/O 2010 - SEO site advice from the experts
Google I/O 2009 - Site Review by the Experts
Chriss Barr's Feng Shui "Tips for Your Yard"

