(基础)Web服务端脚本编写示例

由于一些插入图片出错…一直都不能正常看。编辑文章这个应该把代码灰色在明显一点-_-…main.html:

<html><head> <title>Welcome to book seller</title></head><body><form action = "process.php" method = "post"><h2>Welcome!</h2><table><tr><td>please input your name</td><td><input type = "text" name = "name" size = "30" /></td></tr><tr><td>please input your address</td><td><input type = "text" name = "address" size = "30" /></td></tr><tr><td>please input your zip</td><td><input type = "text" name = "zip" size = "30" /></td></tr></table><p>please fiil in the quantify field of the following form</p><table border = "border"><tr><th>book</th><th>publisher</th><th>price</th><th>quantitiy</th></tr><tr><td>Web technology</td><td>Springer press</td><td>$5.0</td><td><input type = "text" name = "web_t" size = "7" /></td></tr><tr><td>mathematics</td><td>ACM press</td><td>$6.2</td><td><input type = "text" name = "math" size = "7" /></td></tr><tr><td>principle of OS</td><td>Science press</td><td>$10</td><td><input type = "text" name = "os" size = "7" /></td></tr><tr><td>Theory of matrix</td><td>High education press</td><td>$7.8</td><td><input type = "text" name = "matrix" size = "7" /></td></tr></table><h3>Payment method</h3><p><input type = "radio" name = "payment" value = "cash" chexked = "unchecked" />cash <br/><input type = "radio" name = "payment" value = "cheque" chexked = "unchecked" />cheque <br/><input type = "radio" name = "payment" value = "credit card" chexked = "unchecked" />credit card <br/><input type = "submit" value = "submit" /><input type = "reset" value = "reset" /></p></form></body></html>

process.php:

<html><head><title>This is the output of process.php</title></head><body><?php$name = $_POST["name"];$address = $_POST["address"];$zip = $_POST["zip"];$web_t = $_POST["web_t"];$math = $_POST["math"];$os = $_POST["os"];$matrix = $_POST["matrix"];$payment = $_POST["payment"];if($web_t == "") $web_t = 0;if($math == "") $math = 0;if($os == "") $math = 0;if($matrix == "") $matrix = 0;$web_t_cost = 5.0*$web_t;$math_cost = 6.2*$math;$os_cost = 10*$os;$matrix_cost = 7.8*$matrix;$total_num = $web_t+$math+$os+$matrix;$total_price=$web_t_cost+$math_cost+$os_cost+$matrix_cost;?><?phpprintf("Your name:$name <br/> your address:$address <br/> Your zip:$zip<br/>")?><p/><table border = "border"><tr><th>book</th><th>publisher</th><th>quantity</th><th>total</th></tr><?php if($web_t != 0) { ?><tr><td>Web technology</td><td>Springer press</td><td><?php print($web_t);?></td><td><?php printf("$ %4.2f", $web_t_cost);?></td></tr><?php } ?><?php if($math != 0) { ?><tr><td>mathematics</td><td>ACM press</td><td><?php print($math);?></td><td><?php printf("$ %4.2f", $math_cost); ?></td></tr><?php } ?><?php if($os != 0) { ?><tr><td>Theory of matrix</td><td>High education press</td><td><?php print($os);?> </td><td><?php printf("$ %4.2f", $os_cost); ?></td></tr><?php } ?><?php if($matrix !=0) { ?><tr><td>Theory of matrix</td><td>High education press</td><td><?php print($matrix);?> </td><td><?php printf("$ %4.2f", $matrix_cost); ?></td></tr><?php } ?></table><?php printf("%s has bought %d books<br/>", $name, $total_num) ?><?php printf("%s paid %.4f <br/>", $name, $total_price) ?><?php printf("paid by %s <br/>", $payment) ?><?php$file = fopen("customer.txt", "a");fwrite($file, "$name has bought $total_num books\r\n");fwrite($file, "$name paid $total_price\r\n");fwrite($file, "paid by $payment\r\n");?></body></html>

悠然享受和大自然融合之乐。

(基础)Web服务端脚本编写示例

相关文章:

你感兴趣的文章:

标签云: