Jump to content

Recommended Posts


<html>
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
 <title>Acme Service Company</title>
 </head>
 <body style="font-family: Arial">
 <h1><br>
 Acme Service Company</h1>
 <p>Component Quote Form</p>


 <FORM ACTION="processquote.php" method=post>
 <table border=0>
 <tr>
 <td width=150>Item<br>
  </td>
 <td width=15>Quantity<br>
  </td>
 </tr>
 <tr>
 <td>Service 1</td>
 <td align="center"><input type="text" name="qtys1" size="3" maxlength="3"></td>
 </tr>
 <tr>
 <td>Service 2</td>
 <td align="center"><input type="text" name="qtys2" size="3" maxlength="3"></td>
 </tr>
 <tr>
 <td>Service 3</td>
 <td align="center"><input type="text" name="qtys3" size="3" 
 maxlength="3"></td>
 </tr>
 <tr>
 <td colspan="2" align="center"><br>
 <input type="submit" value="Enter Quote"></td>
 </tr>
 </table>
 </form>


 </body>
 </html>




<html>
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
 <title>Acme Service Company</title>
 </head>
 <body style="font-family: Arial">
 <h1><br>
 Acme Service Company</h1>
 <p> </p>


 <?php
 $qtys1 = $_POST['qtys1'];
 $qtys2 = $_POST['qtys2'];
 $qtys3 = $_POST['qtys3'];


 $prices1 = 5.00;
 $prices2 = 3.00;
 $prices3 = 1.00;


 function values1($qtys1, $prices1) {
$values1 = $qtys1 * $prices1;
return $values1;
echo $values1;
 }
 function values2($qtys2, $prices2) {
$values2 = $qtys2 * $prices2;
return $values2;
 }
 function values3($qtys3, $prices3) {
$values3 = $qtys3 * $prices3;
return $values3;
 }
 function totalquote($values1, $values2, $values3) {
$totalquote = $values1 + $values2 + $values3;
return $totalquote;
 }


 ?>


 <p>Thank you!</p>
 <p>Your Quote for:</p>


 <?php


 echo $qtys1.' service 1<br>';
 echo $qtys2.' service 2<br>';
 echo $qtys3.' service 3<br><br>';


 echo $totalquote.' Quote';
 ?>


 <p>was processed.</p>
 </body>
 </html>
Edited by Ch0cu3r

I apologize.  I am trying to create a form that processes service quotes.  The user inputs the total qty of each service into the form then submits quote.  On the processquote.php it is to take the qtys and multiply them times the cost for each service, then add them to give the user a total quote price.

 

My process displays the qty the user inputs but does not return (echo) the value of the quote (s1 + s2 + s3).

 

Thank you.

 

function values1($qtys1, $prices1) {

$values1 = $qtys1 * $prices1;

return $values1;

echo $values1;

Your code exits the function on the return statement so echo never called.

 

Also those functions a very repetitive.

 

Name your form inputs "qty[1]", "qty[2]" and "qty[3]" so they are posted as an array then your processing becomes a simple loop

$prices = array (
                1 => 5.00,
                2 => 3.00,
                3 => 1.00
            );

          
if (isset($_POST['qty'])) {
    $total = 0;  
    foreach  ($_POST['qty'] as $k => $qty) {
        $value = $qty * $prices[$k];
        echo "Service $k : $value<br>";
        $total += $value;    // add value to the total
    }
    echo "Total : $total";
}
Edited by Barand

Thank you GURU the array did work.  I did not want to give the value of each individual item just a total.  I redid the form and process to this which appears to work fine.  Again I am very new to PHP - How hard would this be to scale from 12-1200 line items for quotes?

 

 

<html>
<head>
<title>
</title>
</head>
<body>
 
<h1>ACME Service Company</h1>
 
<h2>Quote Form</h2>
 
<form action="processquote3.php" method=post>
 
<table border=0><tr><td bgcolor="CCCCCC">ITEM</td>
<td bgcolor="CCCCCC">QUANTITY</td></tr>
 
<tr>
<td>Service 1</td><td align="center"><input type="text" name="s1qty" size=3 maxlength=3> </td></tr>
<tr><td>Service 2</td><td align="center"><input type="text" name="s2qty" size=3 maxlength=3></td></tr>
<tr><td>Service 3</td><td Align="center"><input type="text" name="s3qty" size=3 maxlength=3></td></tr>
 
</table>
 
<input type=submit value="Submit Quote">
 
</form>
 
</body>
</html>

 

 

<HTML>
<HEAD><TITLE>ACME Service Company - Quote Results</TITLE>
</HEAD>
<BODY>
<H1>ACME Service Company</H1>
<H2>Quote Results</H2>
 
<?PHP
$s1qty = $_POST['s1qty'];
$s2qty = $_POST['s2qty'];
$s3qty = $_POST['s3qty'];
 
 
echo "<P>Quote Processed.";
echo date("H:i, jS F");
echo "<br><br>";
echo "Service 1:  ".$s1qty."<BR>";
echo "Service 2:  ".$s2qty."<BR>";
echo "Service 3:  ".$s3qty."<BR>";
 
$totalqty = 0;
$totalamount = 0.00;
 
define("SERVICE1PRICE", 10);
define("SERVICE2PRICE", 7);
define("SERVICE3PRICE", 2);
 
 
$totalqty = $s1qty + $s2qty + $s3qty;
$totalamount = $s1qty * SERVICE1PRICE 
                        + $s2qty * SERVICE2PRICE
                        + $s3qty * SERVICE3PRICE;
$totalamount = number_format($totalamount, 2);
echo "<BR>\n";
echo "Items ordered:                 ".$totalqty."<br><br>\n";
echo "Subtotal:                         ".$totalamount."<BR><br>\n";
$taxrate = 0.10;    // local sales tax is 10% here
$totalamount = $totalamount * (1+$taxrate);
$totalamount = number_format($totalamount, 2);
echo "Total Quoted Including Tax: $".$totalamount."<BR>\n";
?>
</BODY>
</HTML>
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.