Loading...


bookmark - More Advice Needed From Php Experts.

More Advice Needed From Php Experts.

 
 Discussion by mrdee with 3 Replies.
 Last Update: April 24, 2012, 3:16 pm
 
bookmark - More Advice Needed From Php Experts.  
Quickly Post to More Advice Needed From Php Experts.  w/o signup Share Info about More Advice Needed From Php Experts.  using Facebook, Twitter etc. email your friend about More Advice Needed From Php Experts. Print
Reply / Comment New Discussion / Topic Share / Bookmark E-Mail a Friend Print

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

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

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.

   Mon Feb 20, 2012    Reply         

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.

   Thu Feb 23, 2012    Reply         

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:

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?

   Thu Feb 23, 2012    Reply         


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.

   Tue Apr 24, 2012    Reply         

Quickly Post to More Advice Needed From Php Experts.  w/o signup Share Info about More Advice Needed From Php Experts.  using Facebook, Twitter etc. email your friend about More Advice Needed From Php Experts. Print
Reply / Comment New Discussion / Topic Share / Bookmark E-Mail a Friend Print

Similar Topics:

Php In Five Minutes

A five minute introduction to PHP If you are like me, you are intimidated by long, drawn-out tutorials that ask you to write a lot of code. I am a purpose driven learner. Any programming learning that I do is what is needed to accomplish a particular task, so ...more

   12-Nov-2008    Reply         

What Is Php Description

can someone tell me what is "PHP" itself? why not we creating new programing language like trap17 language? it just an idea for ALL trap17 exactly who use PHP language ...more

   24-Jun-2009    Reply         

Php Upload Files To Secure Director...

Hello all you great PHP peeps. I'm trying to upload a few PDF documents that I scanned for the clients, like invoices, confidentiality agreements, etc. I want them to register, login, and be able to see their profile and documents they have access to. I will either FTP the files via Filezilla ...more

   30-Oct-2009    Reply         

A Question About The Php Mail() Function    A Question About The Php Mail() Function (12) (0) Php Register Form Validation Help   Php Register Form Validation Help