21,886
社区成员
发帖
与我相关
我的任务
分享
<?php
//获得连接
$db = mysql_connect("localhost", "root", "root") or die(mysql_error());
//echo "Connected to MySQL<br/>";
//连接数据库
mysql_select_db("test") or die(mysql_error());
//echo "Connected to Database";
//查询数据,并用表格显示出来
@$checked = $_POST['checked'];
@$result = mysql_query("select * from books",$db);
echo "<table border=1>\n";
echo "<tr>
<td>isbn</td>
<td>author</td>
<td>title</td>
<td>price</td>
";
echo "</tr>\n";
//循环遍历
while ($myrow = mysql_fetch_row($result)){
printf("<tr>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>", $myrow[0], $myrow[1],$myrow[2],$myrow[3]);
}
echo "</table>\n";
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<form action="" name=""><br/>
<br/>
<input type="button" value="查询" name="submit"/>
<input type="text" name="checked"/>
</form>
</body>
</html>
<?php
//获得连接
$db = mysql_connect("localhost", "root", "root") or die(mysql_error());
//echo "Connected to MySQL<br/>";
//连接数据库
mysql_select_db("test") or die(mysql_error());
//echo "Connected to Database";
//查询数据,并用表格显示出来
// @$checked = $_POST['checked'];
// @$result = mysql_query("select * from books",$db);
// @$result = mysql_query("select * from books where isbn='$checked' ");
if(isset($_POST['checked'])){
@$result = mysql_query("select * from books where isbn='$checked'",$db);
echo "<table border=1>\n";
echo "<tr>
<td>isbn</td>
<td>author</td>
<td>title</td>
<td>price</td>
";
echo "</tr>\n";
//循环遍历
while ($myrow = mysql_fetch_row($result)){
printf("<tr>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>", $myrow[0], $myrow[1],$myrow[2],$myrow[3]);
}
echo "</table>\n";
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<form action="" name="post"><br/>
<br/>
<input type="submit" value="查询" name="submit"/>
<input type="text" name="checked"/>
</form>
</body>
</html>