web技术编程练习题目(2)

2018-11-28 19:33

cash

cheque

credit card

服务器端代码:

confirm your information

// Get form data values

if(empty($_POST[\else

$web = $_POST[\if(empty($_POST[\else

$math = $_POST[\if(empty($_POST[\else

$os = $_POST[\

if(empty($_POST[\else

$matrix = $_POST[\ $name = $_POST[\ $address = $_POST[\ $zip = $_POST[\

$payment = $_POST[\// Compute the item costs and total cost $web_cost = 5.0 * $web; $math_cost = 6.2 * $math; $os_cost = 10 * $os; $matrix_cost = 7.8 * $matrix; $total_price =

$web_cost

+ $math_cost +

$os_cost

+

$matrix_cost;

$total_items = $web + $math + $os + $matrix;

// Return the results to the browser in a table ?>

Customer:

$name

address: $address

zip: $zip

\ ?>

Order

Information

book publisher price total cost

=

%quot

center %quot>

Web technology Springer press $5.0 $web_cost \ ?>

if($math) print(\align

=

%quot

center %quot>

mathematics ACM press $6.2 $math_cost \

=

%quot

center %quot> principle of OS Science press $10

$os_cost \

if($matrix) print(\align

=

%quot

center %quot >

Theory of matrix High education press $7.8 $matrix_cost \

(\

has

bought

$total_items books
\

printf (\$total_price);

print (\ ?>

$fo=fopen(\

fwrite($fo,\has bought $total_items books,$name paid $total_price dollars,paid by $payment.\\r\\n\fclose($fo); ?> 实验三: Main.php代码:

~处理页面~

mysql_connect(\

if(!$conn) { die('Could

not connect:' . mysql_error());

}

?>

--------Create

database-------- */

$DB = \数据库名为Book_Seller

//判断数据库是否存在,

访问系统数据库information_schema

mysql_select_db(\a\or die(\选择失败!\//访问系统数据库 $sql =

\

schema_name from schemata limit 0,30\ $result_db

=

mysql_query($sql,$conn);

$bo = false;//创建bool型变量,用以判断

while($result

=

mysql_fetch_array($result_db,MYSQL_BO

TH)) {

//echo

$result[\

if($result[\== $DB)//数据库已存在,跳过就好啦~

{ $bo = true; break;

}

}

//开始判断

if(!$bo)//$bo=false,即该

数据库不存在,需要创建;存在的话就不管了

{

if(mysql_query(\database

Book_Seller\创建成功

{ //echo

\ } else { echo \

creating datablse: \ exit;

}

}

/* --------Create table in

Book_Seller database-------- */ //Use database $er =

mysql_select_db(\ if(!$er) { echo \_ Could not select the database\

exit;

}

//判断表是否存在,有三

个表,User,Book,Order_form,建个数组用循环语句实现 $tables = array(\\

$sqls = array(//User表语句

\table User(name varchar(20)

primary key not null, address varchar(100) not null, zip varchar(10) )\表语句

\

book varchar(20) primary key not null, publisher varchar(50) not null,

price double)\表语句 \

id int not null auto_increment primary key, name varchar(20) not null, book varchar(20) not null, quantity int not null,

foreign key (name) references User(name), foreign key (book) references Book(book))\); for($i=0; $i<3; $i++)//遍历数组

{

//判断表是否存在

if(mysql_num_rows(mysql_query(\ow tables like '\不存在,建表 {

$sql

=

$sqls[$i];

if(mysql_query($sql, $conn)) { //echo

$tables[$i] . \创建成功\

}

else { echo $tables[$i] . \创建失败\

exit;

}

}

}

?>

//查询用户是否存在

$result

=

mysql_query(\count(*) as num from User where name='\. $_POST['name'] . \ $r

=

mysql_fetch_array($result);

if($r[\< 1)//该用户不存在,添加

{

$sql = \into

User values('\$_POST['name'] .\$_POST['address'] .\ if(!mysql_query($sql, $conn))

{ die('ERROR: ' .

mysql_error());

}

}

else //用户存在,修改信

息 {

$sql = %user set address='\$_POST['zip'] .\

where

name='\

$_POST['name'] .\

if(!mysql_query($sql, $conn))

{ die('ERROR: ' .

mysql_error());

} }

/* ----------插入数据,第

二张表 Book------------ */ //为书名建数组

$books

=

array(\

technology\of

OS\

//查询书籍是否存在,4本书 //Web technology

$result

=

mysql_query(\count(*) as num from Book where book='\ $r

=

mysql_fetch_array($result);

if($r[\< 1)//书籍不

存在,添加

{

$sql = \into

Book values('\$books[0] .\press','5.0')\ if(!mysql_query($sql, $conn))

{ die('ERROR: ' .

mysql_error());

}

}

//mathematics

$result

=

mysql_query(\count(*) as num from Book where book='\ $r

=

mysql_fetch_array($result);

if($r[\< 1)//书籍不存在,添加

{

$sql = \into Book values('\$books[1]

.\

press','6.2')\

if(!mysql_query($sql, $conn))

{ die('ERROR: ' .

mysql_error());

}

}

//principle of OS

$result

=

mysql_query(\count(*) as num from Book where book='\

$r = mysql_fetch_array($result);

if($r[\< 1)//书籍不存在,添加

{

$sql = \into Book values('\$books[2] .\press','10')\ if(!mysql_query($sql, $conn))

{ die('ERROR: ' .

mysql_error());

}

}

//Theory of matrix

$result

=

mysql_query(\count(*) as num from Book where book='\ $r

=

mysql_fetch_array($result);

if($r[\< 1)//书籍不存在,添加 {

$sql = \into Book values('\$books[3]

.\

education press','7.8')\

if(!mysql_query($sql, $conn))

{ die('ERROR: ' .

mysql_error());

}

}

/* ----------插入数据,第三张表 Order_form------------ */ //建数量数组

$quantities

=

array($_POST['web'],$_POST['math'],$_POST['os'],$_POST['matrix']); //检查数量项是否为空。不为空则添加进表,为空则不管

for($i=0; $i<4; $i++) {

if(!empty($quantities[$i]))

{ //判断数据库是否存在此条信息

$result

=

mysql_query(\count(*) as num from Order_form where name='\$_POST['name'] .\and book='\

$books[$i] .\

$r

=

mysql_fetch_array($result); if($r[\< 1)//书籍不存在,添加

{

$sql

=

\values('\$_POST['name'] .\

$books[$i] .\

if(!mysql_query($sql, $conn))

{

die('ERROR: ' . mysql_error());

} }

else //书籍存在,更改数量信息

{

$sql

=

\$quantities[$i] .\where name='\$_POST['name'] .\and

book='\

$books[$i] .\

if(!mysql_query($sql, $conn))

{

die('ERROR: ' . mysql_error());

} } }

}

?>

//关闭连接 mysql_close($conn); ?>

//select.php

订单查询





if(isset($_POST['submit'])) { ?>

//建立连接 $conn =

mysql_connect(\ if(!$conn) { die('Could

not connect:' . mysql_error());

}

//Use database $er =

mysql_select_db(\

if(!$er) { die('ERROR:

'

. mysql_error()); }

?>

$sql = \o.name

name,o.book book,b.publisher

publisher,o.quantity quantity,b.price price from

book

b,order_form

o

where

b.book=o.book and o.name='\

$_POST['name'] .\

$result =

mysql_query($sql, $conn); if(!$result) {

die('ERROR: '

.

mysql_error());

}

//总金额存放处 $allcost = 0.0;

//显示结果

print \查询结果:\

$num

=

mysql_num_rows($result);

if($num < 1)//结果集为空 {

print \该用户没有

订单\

}else {

//开始画表格 print

\

border='1' cellspacing='0' cellpadding='0'>\

//第一行标题 print \

align='center'>\ print \ print \ print \ print \

print \ //查询内容 while($row = mysql_fetch_assoc($result))

{

print \align='center'>\

print

\

$row['name'] .\

print \$row['book'] .\ print \$row['publisher'] .\

print

\

$row['quantity'] .\ print \ $allcost +=

$row['quantity'] * $row['price'];

}

//显示总金额

print \align='right'>\

print

\colspan='4'>总金额: \

print \ print \

}

?>

?>

}

?>


web技术编程练习题目(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:一年级语文上册复习课教案

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: