php访问mysql无法读取数据 20
●reach.html<html><head><title>Book-O-RamaCatalogSearch</title></head><body><h1>Book-O...
●reach.html
<html>
<head>
<title>Book-O-Rama Catalog Search</title>
</head>
<body>
<h1>Book-O-Rama Catalog Search</h1>
<form action="results.php" method="post">
Choose Search Type:<br />
<select name="searchtype">
<option value="author">Author</option>
<option value="title">Title</option>
<option value="isbn">ISBN</option>
</select>
<br />
Enter Search Term:<br />
<input name="searchterm" type="text">
<br />
<input type="submit" value="Search">
</form>
</body>
</html>
●results.php
<html>
<head>
<title>Book-O-Rama Search Results</title>
</head>
<body>
<h1>Book-O-Rama Search Results</h1>
<?php
// create short variable names
$searchtype=$_POST['searchtype'];
$searchterm=$_POST['searchterm'];
$searchterm= trim($searchterm);
if (!$searchtype || !$searchterm)
{
echo 'You have not entered search details. Please go back and try again.';
exit;
}
if (!get_magic_quotes_gpc())
{
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
}
$connection=mysql_connect ("localhost","root","123");
mysql_select_db("myshop",$connection);
$result=mysql_query("select * from books where ".$searchtype." like '%".$searchterm."%'",$connection);
$num_results= mysql_num_fields($result);
echo '<p>Number of books found: '.$num_results.'</p>';
for ($i=0; $i<$num_results; $i++)
{
$row = mysql_fetch_row($result);
echo '<p><strong>'.($i+1).'. Title: ';
echo htmlspecialchars(stripslashes($row['title']));
echo '</strong><br />Author: ';
echo stripslashes($row['author']);
echo '<br />ISBN: ';
echo stripslashes($row['isbn']);
echo '<br />Price: ';
echo stripslashes($row['price']);
echo '</p>';
}
mysql_close($connection);
?>
</body>
</html>
Describe books
+--------+------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+------------+------+-----+---------+-------+
| isbn | char(13) | NO | PRI | NULL | |
| author | char(50) | YES | | NULL | |
| title | char(100) | YES | | NULL | |
| price | float(4,2) | YES | | NULL | |
+--------+------------+------+-----+---------+-------+ 展开
<html>
<head>
<title>Book-O-Rama Catalog Search</title>
</head>
<body>
<h1>Book-O-Rama Catalog Search</h1>
<form action="results.php" method="post">
Choose Search Type:<br />
<select name="searchtype">
<option value="author">Author</option>
<option value="title">Title</option>
<option value="isbn">ISBN</option>
</select>
<br />
Enter Search Term:<br />
<input name="searchterm" type="text">
<br />
<input type="submit" value="Search">
</form>
</body>
</html>
●results.php
<html>
<head>
<title>Book-O-Rama Search Results</title>
</head>
<body>
<h1>Book-O-Rama Search Results</h1>
<?php
// create short variable names
$searchtype=$_POST['searchtype'];
$searchterm=$_POST['searchterm'];
$searchterm= trim($searchterm);
if (!$searchtype || !$searchterm)
{
echo 'You have not entered search details. Please go back and try again.';
exit;
}
if (!get_magic_quotes_gpc())
{
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
}
$connection=mysql_connect ("localhost","root","123");
mysql_select_db("myshop",$connection);
$result=mysql_query("select * from books where ".$searchtype." like '%".$searchterm."%'",$connection);
$num_results= mysql_num_fields($result);
echo '<p>Number of books found: '.$num_results.'</p>';
for ($i=0; $i<$num_results; $i++)
{
$row = mysql_fetch_row($result);
echo '<p><strong>'.($i+1).'. Title: ';
echo htmlspecialchars(stripslashes($row['title']));
echo '</strong><br />Author: ';
echo stripslashes($row['author']);
echo '<br />ISBN: ';
echo stripslashes($row['isbn']);
echo '<br />Price: ';
echo stripslashes($row['price']);
echo '</p>';
}
mysql_close($connection);
?>
</body>
</html>
Describe books
+--------+------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+------------+------+-----+---------+-------+
| isbn | char(13) | NO | PRI | NULL | |
| author | char(50) | YES | | NULL | |
| title | char(100) | YES | | NULL | |
| price | float(4,2) | YES | | NULL | |
+--------+------------+------+-----+---------+-------+ 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询