PHP表单计算问题请教?如何接收单选按钮和复选框传过来的值?

向大牛学习人工智能 2010-03-12 08:20:47
下面是form.html
要求写出cost.php可以接收form传过来的值,包括姓名、电话号码、单选按钮和复选框的值。

<html>
<head>
<title>Dodgy Health Insurance - Premium Calculator</title>
<link href="styles.css" rel="stylesheet">
</head>
<head></head>
<body>
Dodgy Health Insurance - Premium Calculator
<br>Welecome to Dodgy Health Insurance.Complete the form below to calculate the annual premium you would pay for one of our packages.
<FORM action="cost.php" METHOD=post>
First name:<INPUT TYPE=TEXT NAME="fname"><BR>
Last name:<INPUT TYPE=TEXT NAME="lname"><BR>
Phone number:<INPUT TYPE=TEXT NAME="pnumber"><BR>
Hospital cover: <br>
<INPUT TYPE=RADIO NAME="hospital" VALUE="Individual">Individual<br>
<INPUT TYPE=RADIO NAME="hospital" VALUE="Couple">Couple<br>
<INPUT TYPE=RADIO NAME="hospital" VALUE="Family">Family <br>
Extra health cover: <br>
<INPUT TYPE=CHECKBOX NAME="extra[]" VALUE="Dental">Dental<br>
<INPUT TYPE=CHECKBOX NAME="extra[]" VALUE="Optical">Optical<br>
<INPUT TYPE=CHECKBOX NAME="extra[]" VALUE="Physiotherapy">Physiotherapy<br>
<INPUT TYPE=CHECKBOX NAME="extra[]" VALUE="Clinical psychology">Clinical psychology<br>
<INPUT TYPE=CHECKBOX NAME="extra[]" VALUE="Other therapies ">Other therapies <br>
<INPUT TYPE=HIDDEN NAME="cost" VALUE= "cost"><br>
<INPUT TYPE=SUBMIT VALUE= "Submit"><INPUT TYPE=reset VALUE= "Reset">
</FORM>
</body>
</html>

...全文
501 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
大家帮帮我啊,非常感谢!!!
我的QQ:731083964
  • 打赏
  • 举报
回复
我的QQ:731083964 楼上能否加我的QQ?咱们通过QQ交流好吗?
谢谢楼上,我翻译了一下:
创建列表页面
  创建一个PHP文件命名为list.php以下细节中所有课程中:
  课程名称、身份证号码,在周开始日期、长度、成本和教练的名字。
  这个记录应根据课程的身份证号码顺序。
  货币价值应展示了美元($)和两个标志小数。你必须在你的任何一种货币价值的格式的PHP代码。不要依靠货币价值函数的格式。
  日期应表现为每月的数字(0领先于为单数天),跟着由姓名,紧随其后的是年度表现为4位数。你必须格式的任何日期在你的PHP代码的价值。不要依靠日期值函数的格式。
heyli 2010-03-14
  • 打赏
  • 举报
回复
楼主帮我翻译一下 我去吃早餐
heyli 2010-03-14
  • 打赏
  • 举报
回复

create database assignment2;
use assignment2;
create table Instructor(
instructor_id int(10) not null auto_increment,
instructor_name varchar(30),
instructor_phone varchar(30),
primary key(instructor_id)
);
insert into Instructor values('','Kerry Walters','5294 1140');
insert into Instructor values('','John Jacobson','5407 1006');
insert into Instructor values('','Jessica Cameron','5499 7387');
insert into Instructor values('','Bruce Phillips','5314 4212');
create table course(
course_id int(10) not null auto_increment,
course_name varchar(30),
instructor_id int(10),
course_start datetime,
course_weeks bigint,
course_cost decimal(5,2),
primary key(course_id)
);
insert into course values('','Introductory Pottery',3,' 2009-11-09',6,180.00);
insert into course values('','Cake Decorating',1,' 2009-10-26',8,240.00);
insert into course values('','Advanced Pottery',3,' 2010-01-11',6,180.00);
insert into course values('','Introductory Photography',4,' 2009-20-26',6,150.00);
insert into course values('','Advanced Photography',4,'2010-01-18',6,150.00);
insert into course values('','Signwriting',2,'2010-01-11',8,240.00);

Grant all
On assignment2
To mmst12009 identified by "mmst12009"

list.php要的内容看不太懂 我再看下
  • 打赏
  • 举报
回复
大家快帮帮我,非常感谢大家!
餅餅 2010-03-13
  • 打赏
  • 举报
回复
<?php
$firstName=$_POST['fname']; //First name
$lastName=$_POST['lname'];//Last name
$phoneNumber=$_POST['pnumber'];//Phone number
$hospitalCover=$_POST['hospital'];//Hospital cover
$extraHealthCover=$_POST['extra'];//Extra health cover

echo $firstName."<br>";
echo $lastName."<br>";
echo $phoneNumber."<br>";
echo $hospitalCover."<br>";
print_r($extraHealthCover);
?>
heyli 2010-03-13
  • 打赏
  • 举报
回复


else if ($hospital=="Family"){
$total= 2500 + (50 * $count) * 3;
echo "You paid a total " . $total; //家庭
}



改为

else if ($hospital=="Family"){
$total= 3200 + (50 * $count) * 3;
echo "You paid a total " . $total; //家庭
}


写错了
heyli 2010-03-13
  • 打赏
  • 举报
回复
根据参加医疗保险的对象不同 附加医疗保险的计算方式也不同 每一项的价钱是$50 家庭他是以三个人来算 那夫妻呢 我是帮你按两个人来算 如果资料没有填写就要出现提示

<?php
@$fname=$_POST["fname"];
@$lname=$_POST["lname"];
@$pnumber=$_POST["pnumber"];
@$hospital=$_POST["hospital"];
@$extra=$_POST["extra"];

if ($fname=="" or $lname=="" or $pnumber=="" or $hospital==""){ //资料没有填写完整
echo "Provide you with incomplete information";
exit();
}

if ($extra==""){ //计算一共选了多少项附加
$count=0;
}else{
$count = count($extra);
}

if ($count==0){
echo "You selected no extra cover <br>"; //提示不用支付其它项
}
if ($hospital=="Individual"){ //判断是以那种身份参加医疗保险
$total= 1300 + 50 * $count;
echo "You paid a total " . $total; //个人
}else if ($hospital=="Couple"){
$total= 2500 + (50 * $count) * 2;
echo "You paid a total " . $total; //夫妻
}else if ($hospital=="Family"){
$total= 2500 + (50 * $count) * 3;
echo "You paid a total " . $total; //家庭
}
?>

有什么错接着说
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 coolesting 的回复:]
11楼叫你建立两张表, 填写测试数据。

12楼叫你写个list.php ,并要正确显示数据格式,还添加一个测试帐号。
[/Quote]
11楼和12楼都是我,都是楼主我,我想让大家帮我把list.php这个程序正确地写出来,非常感谢!
前面接收单选按钮和复选框传过来的值的问题已经让9楼帮我解决了。现在的问题我在11楼和12楼里面说清楚了,就是写出list.php这个程序。非常感谢大家的帮助,尤其感谢9楼。
  • 打赏
  • 举报
回复
估计这个要用到ifelse语句判断,我不太会用。再举个例子:
Example 3. A family wants to buy hospital cover, optional optical cover and optional physiotherapy
cover. The cost is $3 500.
$3 200 + ($50 + $50)  3 = $3 500
  • 打赏
  • 举报
回复
非常感谢楼上,非常感谢6楼,6楼能否再根据下面的要求帮我计算出费用cost?

If the customer does not select any optional components in the form, the results page should display the
message ‘You selected no extra cover' instead of the list of extra cover.
The following information can be used to calculate the premium:
 Table 1-1 lists the cost of hospital cover for individuals, couples and families.
 Each item of optional extra cover costs $50 for individuals i.e. $50 for dental, $50 for optical, and so on.
 The cost of optional extra cover for couples is 2 times the cost of optional extra cover for
individuals i.e. $100 for dental, $100 for optical, and so on.
 The cost of optional extra cover for families is 3 times the cost of optional extra cover for
individuals i.e. $150 for dental, $150 for optical, and so on.

Table 1-1. Hospital cover costs
Type of hospital cover Cost
Individual $1 300
Couple $2 500
Family $3 200

If the prospective customer does not supply a first name, last name, phone number or type of hospital
cover on the form, the results page should tell the customer that the missing detail is required and ask
him or her to click the browser's Back button and try again. Processing of the form should stop at that
point.
The following examples illustrate how the premium is calculated.
Example 1. An individual wants to buy hospital cover, optional dental cover, optional optical cover and
optional physiotherapy cover. The cost is $1 450.
$1 300 + $50 + $50 + 50 = $1 450
骄傲青蛙 2010-03-13
  • 打赏
  • 举报
回复
11楼叫你建立两张表, 填写测试数据。

12楼叫你写个list.php ,并要正确显示数据格式,还添加一个测试帐号。
by_baby 2010-03-13
  • 打赏
  • 举报
回复
最好是先判断一下传过来的值
  • 打赏
  • 举报
回复
Adding a user to MySQL
Use phpMyAdmin to add a new user named student with all privileges on all tables in the assignment2
database. Set the user's password to mmst12009.
It is very important that you create this user with the name, password and privileges that have been
specified because the marker will test your code with these details. If you give your user a different
name, a different password or different privileges, your code will fail to work on the marker's computer.
Creating the list page
Create a PHP file named list.php that retrieves the following details for all courses in the database: the
course ID number, name, starting date, length in weeks, cost and instructor name.
Display these details in an XHTML table with the column headings that appear in Figure 2–1. The
records should be sorted by course ID number in ascending order.
Currency values should be displayed with a leading dollar sign ($) and two decimal places. You must
format any currency values in your PHP code. Do not rely on MySQL to format currency values.
Dates should be displayed as the day of the month in digits (no leading 0 for single-digit days), followed
by the full name of the month, followed by the year represented as 4 digits. You must format any date
values in your PHP code. Do not rely on MySQL to format date values.

  • 打赏
  • 举报
回复
非常感谢9楼,程序写得非常好。现在还有一个问题:
Craft School is a fictitious institution that runs hobby classes. The aim of this question is to a build a
MySQL database and a PHP page that retrieves and formats records from the store’s database of courses
and instructors.
Creating the database
Start phpMyAdmin and create a new database named assignment2. Within the assignment2 database,
create a table named instructors with the fields shown in Table 2–1. Create a primary key on the
instructor_id field and set the auto_increment option for that field. Fill the table with the data shown in
Table 2–2 and save the table.
Table 2–1: Fields for the instructors table
Field name Data type Field description
instructor_id unsigned int ID number that uniquely identifies an instructor
instructor_name varchar(30) Instructor's name
instructor_phone varchar(20) Instructor's phone number
Table 2–2: Data for the instructors table
instructor_id instructor_name instructor_phone
1 Kerry Walters 5294 1140
2 John Jacobson 5407 1006
3 Jessica Cameron 5499 7387
4 Bruce Phillips 5314 4212
Create a second table named courses with the fields shown in Table 2–3. Create a primary key on the course_id field and set the auto_increment option for that field. Fill the table with the data shown in Table 2–4 and save the table.
Table 2–3: Fields for the courses table
Field name Data type Field description
course_id unsigned int ID number that uniquely identifies a course
course_name varchar(30) Name of course
instructor_id unsigned int ID number that uniquely identifies the course instructor
course_start date Starting date of course
course_weeks unsigned int Length of course in weeks
course_cost unsigned decimal(5,2) Cost of course
Table 2–4: Data for the courses table
course_id course_name instructor_id course_start course_weeks course_cost
1 Introductory Pottery 3 2009-11-09 6 180.00
2 Cake Decorating 1 2009-10-26 8 240.00
3 Advanced Pottery 3 2010-01-11 6 180.00
4 Introductory Photography 4 2009-10-26 6 150.00
5 Advanced Photography 4 2010-01-18 6 150.00
6 Signwriting 2 2010-01-11 8 240.00
床上等您 2010-03-12
  • 打赏
  • 举报
回复
cost.php

$arr_chk=$_POST['extra'];
$str_rdo=$_POST['hospital'];

print_r($arr_chk);//数组
echo $str_rdo;//string
w342229068 2010-03-12
  • 打赏
  • 举报
回复
受教了
  • 打赏
  • 举报
回复
大家能否帮我写出完整的cost.php代码?
heyli 2010-03-12
  • 打赏
  • 举报
回复
$_POST["xxx"]
xxx换成你表单想取值的name
床上等您 2010-03-12
  • 打赏
  • 举报
回复
$arr_chk=$_POST['extra'];
$str_rdo=$_POST['hospital'];

print_r($arr_chk);//数组
echo $str_rdo;//string

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧