我正在尝试设置一个php脚本,在这种情况下从Web表单中输入几个下拉框,(附加内容和培训师),并在总计的基础上累计20%的税。我不确定如何做总计,而且20%也需要另外我得到第80行的错误,这是最后一个结束标记(我是非常新的php)
<?php
$extras = array(
'Laces' => 5,
'Shoe Polish' => 10,
'In-souls' => 15
);
$trainers = array(
'Lacoste' => 50,
'K-Swiss' => 45,
'Puma' => 59,
'Converse' => 65
);
{
$firstname = $_POST['firstname'];
echo "Firstname $firstname <br />\n";
}
{
$lastname = $_POST['lastname'];
echo "Lastname $lastname <br />\n";
}
{
$add1 = $_POST['add1'];
echo "$add1 <br />\n";
}
{
$add2 = $_POST['add2'];
echo "$add2 <br />\n";
}
{
$postcode = $_POST['postcode'];
echo "$postcode <br />\n";
}
{
$email = $_POST['email'];
echo "Contact Email Address $email <br />\n";
}
{
$telephone = $_POST['telephone'];
echo "Contact Telephone Number $telephone <br />\n";
}
{
$contact = $_POST['contact'];
echo "You would like to be contacted by $contact <br />\n";
}
{
$trainers = $_POST['trainers'];
echo "The trainers you would like are $trainers <br />\n";
}
{
$extras = $_POST['extras'];
echo "The extras you would like are $extras <br />\n";
}
$extraCost = 0;
$trainerCost= 0;
$totalCost= 0;
$extra = $_POST['extras'];
if (in_array($extra, $extras)) {
$runningCost = $extras[$extra];
echo "The cost of your extras are $extraCost<br />\n";
$extra = $_POST['trainers'];
if (in_array($trainer, $trainers)) {
$runningCost = $trainers[$trainer];
echo "The cost of your Trainers are $trainerCost<br />\n";
}
?>
非常感谢你!
答案 0 :(得分:2)
$extraValues = array(
'Laces' => 5,
'Shoe Polish' => 10,
'In-souls' => 15
);
$trainerValues = array(
'Lacoste' => 50,
'K-Swiss' => 45,
'Puma' => 59,
'Converse' => 65
);
if(isset($_POST['firstname'])){
$firstname = $_POST['firstname'];
echo "Firstname $firstname <br />\n";
}
if(isset($_POST['lastname'])){
$lastname = $_POST['lastname'];
echo "Lastname $lastname <br />\n";
}
if(isset($_POST['add1'])){
$add1 = $_POST['add1'];
echo "$add1 <br />\n";
}
if(isset($_POST['add2'])){
$add2 = $_POST['add2'];
echo "$add2 <br />\n";
}
if(isset($_POST['postcode'])){
$postcode = $_POST['postcode'];
echo "$postcode <br />\n";
}
if(isset($_POST['email'])){
$email = $_POST['email'];
echo "Contact Email Address $email <br />\n";
}
if(isset($_POST['telephone'])){
$telephone = $_POST['telephone'];
echo "Contact Telephone Number $telephone <br />\n";
}
if(isset($_POST['contact'])){
$contact = $_POST['contact'];
echo "You would like to be contacted by $contact <br />\n";
}
if(isset($_POST['trainers'])){
$trainers = $_POST['trainers'];
echo "The trainers you would like are $trainers <br />\n";
}
if(isset($_POST['extras'])){
$extras = $_POST['extras'];
echo "The extras you would like are $extras <br />\n";
}
$extraCost = 0;
$trainerCost= 0;
$totalCost= 0;
$extra = $_POST['extras'];
if (array_key_exists($extra, $extraValues)) {
$extraCost = (float) $extraValues[$extra];
echo "The cost of your extras are $extraCost<br />\n";
} // this brace was missing and causing your error
// if this is the name then use array_key_exists in the if statement below
$trainer = $_POST['trainers'];
if (array_key_exists($trainer, $trainerValues)) {
$trainerCost = (float) $trainerValues[$trainer];
echo "The cost of your Trainers are $trainerCost<br />\n";
}
// add 20%, and round to 2 decimal places...
$totalCost = round(($extraCost+$trainerCost+$totalCost)*1.2, 2);