我正在尝试显示我的数据库中的isbn号码,当他们点击其他页面中的图片时出于某些原因我不断收到此错误
注意:未定义的索引:第8行的isbn
<html><title>Employee List</title> <head></head>
<body>
<h1> List of Employees </h1>
<?php
require_once("include/db_connect.php");
$db_link = db_connect("project");
$isbn = $_REQUEST['isbn'];
$query = "SELECT * FROM bookstore WHERE isbn = '$isbn'";
$result = mysql_query($query);
if ($row = mysql_fetch_assoc($result)) {
$isbn = $row['isbn'];
echo "<tr><td><strong>Isbn:</strong>". $isbn. "</td>";
}
?>
</body>
</html>
我的php程序的主程序
<?php require_once("include/db_connect.php"); ?>
<html>
<head><title>Displaying Image files using PHP</title></head>
<body>
<h1>Bookworms Booksite</h1>
<style> @import "css/style.css";</style>
<div id = "nav">
<ul>
<li><a class = "navbutton" href="index.html">Home</a></li>
<li><a class = "navbutton" href="membership.html">Books</a></li>
<li><a class = "navbutton" href="classes.html">Shopping Cart</a></li>
<li><a class = "navbutton" href="">Checkout</a></li>
<li><a class = "navbutton" href="shop.html" id ="current" >About</a></li>
</ul>
</div>
<p></p>
<p></p>
<div id = "sideNav">
<ul>
<li><a href="#home">Enter Bookstore</a></li><br>
<li><a href="#news">Bookstore Administartion</a></li><br>
<li><a href="#contact">Search</a></li>
</ul>
</div>
<?php
$db_link = db_connect("project");
// Retrieve table properties
$fields = mysql_list_fields("project", "bookstore");
$num_columns = mysql_num_fields($fields);
// Make a simple database query to select all columns and rows
$query = "SELECT * FROM bookstore";
$result = mysql_query($query) or die("SQL query failed");
// Display results as an HTML table. Note how mysql_field name
// uses the $fields object to extract the column names
echo '<table border="1" cellpadding = "5" >';
// Display the column names
echo "<tr>";
echo "</tr>";
// Loop over the rows of the table.
// $row contains the information for each row
// Refer to the names of the fields in the table
// Must ahow the path where the image files are held
while ($row = mysql_fetch_assoc($result))
{
echo "<tr>";
$isbn = $row['isbn'];
$title = $row['title'];
echo "<td><a href='bookDetail.php'><img src = 'images/". $row['image']. "'></a></td>";
echo "<a href='bookDetail.php? id= ". $isbn . "'>". $title . "</a><br/>";
echo "<td>". $row['isbn']."</td>";
echo "<td>". $row['title']."</td>";
echo "<td>". $row['author']."</td>";
echo "<td>". $row['pub']."</td>";
echo "<td>". $row['year']."</td>";
echo "<td>". $row['price']."</td>";
echo "</tr>";
}
echo "</table>";
// Free the resources and close the connection
mysql_free_result($result);
mysql_close($db_link);
?>
</body>
</html>
答案 0 :(得分:0)
第8行是这样的:
$isbn = $_REQUEST['isbn'];
因此,您的$ _REQUEST ['isbn']变量未定义。做一个print_r($ _REQUEST);检查您的请求参数。
要使用$ _REQUEST ['isbn'],您需要通过表单调用页面并使用name ='isbn'的字段,否则它将不存在。
答案 1 :(得分:-1)
实际上第8行是“$ _REQUEST ['isbn'];”这与数据库无关。您确定要将参数传递给页面吗?