douyinzha5820 2014-04-30 19:39
浏览 42
已采纳

尝试显示数据库中的数字时未定义的索引

i am trying to display the isbn number from my database when they click an image from another page and for some reason i keep getting this error

Notice: Undefined 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>

main program for my php program

            <?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>
  • 写回答

2条回答 默认 最新

  • drxm72811 2014-04-30 19:44
    关注

    Line 8 is this :

    $isbn = $_REQUEST['isbn'];
    

    Therefore, your $_REQUEST['isbn'] variable is undefined. Do a print_r ($_REQUEST); to check your request parameters.

    To use $_REQUEST['isbn'], you need the page to be called by a form and have a field with name='isbn', otherwise it won't exist.

    More information about forms : http://www.php.net/manual/en/tutorial.forms.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试