PDA

View Full Version : Please help me! Problem: Multiple calculations from multiple drop boxes need adding


mat420
05-02-2008, 05:13 PM
Please help. This is what I have so far http://bartletagency.com/m/x2.php

Now, obviously with business cards there many different options. I need something to calculate on the side the total after picking each drop box option, or if easier, after hitting "calculate total." (preferably with the numbers in a table so I can make it appear by itself right underwear the send button) . Example: 1000 business cards in blue, say, would need to come up at 50 dollars if they pick 3-1, but if they pick 3-22 it needs to come up 60 dollars

if they pick the other color, green, and pick 3-1, the label would need to turn to $55.00, if they pick 3-2 with the color green the label would need to say $65.00

how can i do this please? id love for someone to just add it to that code but that might be too much to ask :) so please tellme how i can do this so i can try to figure it out. everytime i try to add a calculation code to it i mess up the code because i know nothing about PHP or HTML really. I can work with html a lot better than PHP though.

here is the code I have which made up the PHP file i linked you to above.


code:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title>Lesson 3</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
if ($_SERVER['REQUEST_METHOD'] != 'POST'){
$me = $_SERVER['PHP_SELF'];
?>
<h1 align="center">Business Cards</h1>
<form name="form1" method="post" action="<?=$me?>">
<table border="0" align="center" cellpadding="5" cellspacing="0">
<tr>
<td align="right" valign="middle">Quantity:</td>
<td><select name="Quantity: ">
<option value="1000">1000</option>
<option value="2500">2500</option>
<option value="5000">5000</option>
<option value="10,000">10,000</option>

</select>
</td>
</tr>


<tr>
<td align="right" valign="middle">color</td>
<td><select name="color">
<option value="blue">blue</option>
<option value="green">green</option>

</select>
</td>
</tr>

<tr>
<td align="right" valign="middle">3</td>
<td><select name="3">
<option value="small">3-1</option>
<option value="medium">3-2</option>

</select>
</td>
</tr>


<tr>
<td> </td>
<td><input type="submit" name="Submit"
value="Send">
</td>
</tr>
</table>
</form>



<?php

} else {
error_reporting(0);
// initialize a array to
//hold any errors we encounter
$errors = array();
// test to see if the form was actually
// posted from our form
$page = $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
if (!ereg($page, $_SERVER['HTTP_REFERER']))
$errors[] = "Invalid referer<br>\n";
// check to see if a name was entered

if (count($errors)>0) {
foreach($errors as $err)
echo "$err<br>\n";
echo "<br>Please use your browser's Back button to fix.";
} else {
// no errors, so we build our message
switch($_POST['color']){
case 'red':
$recipient = 'mathew420@gmail.com';
break;
case 'green':
$recipient = 'mathew420@gmail.com';
break;
case 'blue':
$recipient = 'mathew420@gmail.com';
break;
default:
$recipient = 'mathew420@gmail.com';
}
$subject = "Widget On Line Order";
$from = stripslashes($_POST['Name']);
$msg = "Message sent by $from\n";
$msg.="\nSize: ".$_POST['size'];
$options=$_POST['options'];
$msg.="\nOptions:";
if ($options)
for ($i=0;$i<count($options);$i++)
$msg.= "\n- $options[$i]";
else
$msg.="\n- None";
$msg.="\nColor: ".$_POST['color'];
$extension=($_POST['extension'])?"Extension: Yes":"Extension: No";
$wallmount=($_POST['wallmount'])?"Wallmount: Yes":"Wallmount: No";
$deskmount=($_POST['deskmount'])?"Deskmount: Yes":"Deskmount: No";
$msg.="\n$extension\n$wallmount\n$deskmount";
$msg.="\n".stripslashes($_POST['MsgBody'])."\n";
if (mail($recipient,$subject,$msg)){
echo "<p>Thanks for your order!</p>";
echo nl2br($msg);
} else
echo "An unknown error occurred.";
}
}
?>
</body>
</html>



thanks so much