南京邮电大学Web技术双语实验三(Web 数据库访问)
文章目录
- 一、 实验目的和要求
- 二、实验环境(实验设备)
- 三、实验原理及内容
- (1)Html首页(index.html):
- (2)数据库连接:
- (3)Sql语句:
- 四、实验小结(包括问题和解决方法、心得体会、意见与建议等)
- (一)实验中遇到的主要问题及解决方法
- (二)实验心得
- (三)意见与建议(没有可省略)
一、 实验目的和要求
中文五号宋体,英文五号Times new roman字体,1.25倍行距
用中文描述本次实验的目的和要求,可参考实验指导书相关描述。
二、实验环境(实验设备)
中文五号宋体,英文五号Times new roman字体,1.25倍行距
硬件:微型计算机
软件:Windows 操作系统、浏览器
三、实验原理及内容
(1)Html首页(index.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>
(2)数据库连接:
<html>
<head>
<title>This is the output of process.php</title>
</head>
<body>
</body>
</html>
(3)Sql语句:
<html>
<head>
<title>porcess_query.php form</title>
</head>
<body>
<?php
$user_name = $_POST["user_name"];
$con = mysql_connect("localhost", "root", "root");
if(!$con)
{
die('Could not connect:'.my_sqlerror());
}
mysql_select_db('myEx', $con);
$result = mysql_query("select name, orders.book, publisher, quantity from orders, books where orders.book = books.book and name = '$user_name'"); //
echo"
name
book
publisher
quantity
";
while($row = mysql_fetch_array($result))
{
echo"";
echo"".$row['name']." ";
echo"".$row['book']." ";
echo"".$row['publisher']." ";
echo"".$row['quantity']." ";
echo" ";
}
echo"
";
mysql_close($con);
?>
</body>
</html>
四、实验小结(包括问题和解决方法、心得体会、意见与建议等)
(一)实验中遇到的主要问题及解决方法
连接数据库时,找不到库函数,配置php ini文件后解决。
(二)实验心得
学习了前端通过php和数据库的连接