Current location: Hot Scripts Forums » Programming Languages » PHP » * this php error has got me very confused *


* this php error has got me very confused *

Reply
  #1 (permalink)  
Old 11-26-03, 01:27 PM
nabi nabi is offline
Newbie Coder
 
Join Date: Sep 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Question * this php error has got me very confused *

Hi,
Can anyone help me with this script...? Or recommend any other "real-time" quotation calculating scripts???


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html><head>
<title>Quotation</title>
</head>
<body style="font-family: Verdana; font-size: 8pt">
<form method="POST">
<p>
<select size="1" name="monitor" style="font-family: Verdana; font-size: 8pt; border-style: solid; border-width: 1">
<option>Choose a Monitor</option>
<option value="lg">lg</option>
<option value="sony">sony</option>
<option value="iiyama">iiyama</option>
</select>
<br>
<input type="text" name="quantity" size="3" maxlength="3" style="font-family: Verdana; font-size: 8pt; border-style: solid; border-width: 1">
</p><p>
<input type="submit" value="Submit" name="submit" style="font-family: Verdana; font-size: 8pt; border-style: solid; border-width: 1">
<input type="reset" value="Reset" name="reset" style="font-family: Verdana; font-size: 8pt; border-style: solid; border-width: 1">
</p>
</form>

<?php

if ($monitor = "lg")
{$price = 90.25;}
else if ($monitor = "sony")
{$price = 80.25;}
else if ($monitor = "iiyama")
{$price = 70.00;}

$sales_tax = .175;
$sub_total = $price * $quantity;
$sales_tax_amount = $sub_total * $sales_tax;
$sales_tax_pct = $sales_tax * 100;
$grand_total = $sub_total + $sales_tax_amount;

$fmt_price = $price;
$fmt_sub_total = $sub_total;
$fmt_sales_tax_amount = $sales_tax_amount;
$fmt_grand_total = $grand_total;

echo "<br>You ordered $quantity of the $monitor monitor(s).";
echo "<br>$monitor are \$$fmt_price each.";
echo "<br>Your subtotal is \$$fmt_sub_total.";
echo "<br>Sales tax is $sales_tax_pct% in this location.";
echo "<br>\$$fmt_sales_tax_amount has been added to your order.";
echo "<br>You owe \$$fmt_grand_total for your monitor.";

?>

</body></html>




I get the following errors when I load it:
Notice: Undefined variable: quantity in C:\Inetpub\web_server_x1\htdocs\do_calculate.php on line 33

Notice: Undefined variable: quantity in C:\Inetpub\web_server_x1\htdocs\do_calculate.php on line 43




I dont understand what seems to be the problem, at first I got too many errors and I only had the patience and the knowledge to come this far with only 2 errors! If you do fix it, then you can use it freely as a quotation!!!

NABSTER
Reply With Quote
  #2 (permalink)  
Old 11-26-03, 04:47 PM
YourPHPPro's Avatar
YourPHPPro YourPHPPro is offline
Community VIP
 
Join Date: Aug 2003
Posts: 430
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by nabi
$sub_total = $price * $quantity;
When the script first runs through, you haven't defined what $quantity is ?

You need to wrap the calculations in a branch so they are not executed until the POST has occured.
Reply With Quote
  #3 (permalink)  
Old 11-27-03, 07:37 AM
fyrestrtr fyrestrtr is offline
Wannabe Coder
 
Join Date: Nov 2003
Posts: 191
Thanks: 0
Thanked 0 Times in 0 Posts
There are quite a lot of problems with that script. To start off

PHP Code:

if ($monitor "lg")

{
$price 90.25;}
else if (
$monitor "sony")
{
$price 80.25;}
else if (
$monitor "iiyama")
{
$price 70.00;} 
All those if conditions will be true. Remember that = is assignment, and == is comparison. You need to fix your if conditions.

Also, the entire script assumes that register_globals is on (and its set to OFF on most PHP installs). You need to replace your variables that are coming in from the form with $_POST['nameofvariable'] -- so $monitor becomes $monitor = $_POST['monitor'];

There is no variable $quantity -- because register globals is off. You need $_POST['quantity'].

Your <form> tag is missing the action attribute.

Add error_reporting(E_ALL); as the first php line.

Start over with the above hints.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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 On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
PHP Dudes - Hi All stuart New Members & Introductions 4 05-03-04 01:22 PM
Realtime PHP Code Obfuscation barrywien General Advertisements 1 11-16-03 06:50 PM
How to convert php generated pages to SE friendly HTML or PHP(SE friendly) -CLASS 101 crippled PHP 1 11-16-03 06:37 AM
PHP Triad/Upload form eddyvlad PHP 6 10-06-03 11:17 PM


All times are GMT -5. The time now is 06:01 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.