Eenvoudig calculator doet het niet

Status
Niet open voor verdere reacties.

Tijssen

Gebruiker
Lid geworden
31 aug 2009
Berichten
50
Ik heb een eenvoudig script en het script doet het niet. Ik gebruik een lokale server en andere scripts doen het prima. Het gaat om een HTML-formulier waarvan de waarden naar een PHP bestand worden geschreven. Wie weet wat er mis gaat?

HTML-formulier
HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=windows-1250">
  <meta name="generator" content="PSPad editor, www.pspad.com">
  <title>Product cost calculator</title>
  </head>
  <body>
   Fill out this form to calculate the costs: <br />
   <form action="handle_calc.php" method="post">
   Price:<input type="text" name="price" size="5"><br />
   Quantity:<input type="text" name="quantity" size="5"><br />
   Discount:<input type="text" name="discount" size="5"><br />
   Tax:<input type="text" name="tax" size="3"><br />
   Shipping method:<select name="shipping">
   <option value="5.00">Slow and steady</option>
   <option value="8.95">Put a move on it</option>
   <option value="19.36">I need it yesterday</option>
   </select>
   <br />
   Number of payment to make: <input type="text" name="payments" size="3" />
   <br />
   <input type="submit" name="submit" value="calculate" />
   </form>
   <!--Calculator.html-->
    
  </body>
</html>

PHP-bestand
PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=windows-1250">
  <meta name="generator" content="PSPad editor, www.pspad.com">
  <title>Product Cost</title>
  </head>
  <body>
   <?php//script hand_calc.php
   /*this script takes value from calculator.html and 
   performs total cost and monthly payments calculations*/
   
   ini_set('display_errors',1);
   error_reporting(E_ALL&~E_NOTICE);
       
   $price=$_POST['price'];
   $quantity=$_POST['quantity'];
   $discount=$_POST['discount'];
   $tax=$_POST['tax'];
   $shipping=$_POST['shipping'];
   $payments=$_POST['payments'];
  
   //calculate the total
   $total=$price*$quantity;
   $total=$total+$shipping;
   $total=$total-$discount;
   
   //Determine the taxrate
   $taxrate=$tax/100;
   $taxrate=$taxrate + 1;
   
   //Factor in the taxrate
     $total=$total*$taxrate;
    
   //calculate the monthly payments
   $monthly=$total/$payments;
    
   //print out the results
   print "you have selected to purchase: <br />
   <b>$quantity</b>widgets at<br />
   $<b>$price</b>price with a <br />
   $<b>$shipping</b> shipping costs and a<br />
   <b> $tax</b>percent tax rate<br />
   After your $<b>$discount</b>discount the ,
   total cost is
   $<b>$total</b>.<br />
   Divided over<b>$payments</b>montly payments,
   that would be $<b>$monthly</b>each.";
   ?>

  </body>
</html>
 
Laatst bewerkt door een moderator:
Wat gaat er fout? Welke foutmeldingen, wat voor output krijg je, wat klopt er niet?
 
Wat gaat er fout? Welke foutmeldingen, wat voor output krijg je, wat klopt er niet?

Dit is de output die ik krijg, geen foutmeldingen. Er zouden i.p.v. de variabelen waarden moeten worden weergegeven.
Ik zie verder dat de eerste regel van de output wegvalt en dat de tekens aan het einde niet zouden moeten worden weergegeven.

$quantitywidgets at
$$priceprice with a
$$shipping shipping costs and a
$taxpercent tax rate
After your $$discountdiscount the , total cost is $$total.
Divided over$paymentsmontly payments, that would be $$monthlyeach."; ?>
 
Laatst bewerkt:
Heb je de site ergens online? Weet je zeker dat PHP ondersteunt wordt?
 
Misschien haken zetten om de tekst die je wilt uitprinten bij de print-functie?

groeten vreugde
 
Laatst bewerkt:
maak van print


print <<<EDNHTML

zet dan bij $<B>$prijs</b> dit neer ${$prijs}
dit bij iedere $output

en eindig met ENDHTML; zonder spatie of iets er voor of achter endhtml;
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan