试图从数据库显示数字时未定义索引


undefined index when trying to display number from database

我试图从我的数据库显示isbn号时,他们点击另一个页面的图像,由于某种原因,我一直得到这个错误

注意:未定义index: isbn on line 8

            <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>

第8行是这样的:

$isbn = $_REQUEST['isbn'];

因此,$_REQUEST['isbn']变量是未定义的。执行print_r ($_REQUEST);查看请求参数

要使用$_REQUEST['isbn'],您需要页面被表单调用并且有一个name='isbn'的字段,否则它将不存在。

关于表单的更多信息:http://www.php.net/manual/en/tutorial.forms.php

实际上第8行是"$_REQUEST['isbn'];"这与数据库无关。您确定要将参数传递给页面吗?