undefined index when trying to display number from database

user3482470

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

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Undefined index PHP/MySQL when trying to query database

When trying to display property from JSON data gives undefined

Undefined index when trying to get result from JSON to array

Getting an undefined error when trying to print results from database

fix the display format in php when trying to retrieve data from database

Incorrect number of binding when trying to delete from a database (Tkinter, SQLite)

Undefined index when printing data from mysql database?

Undefined index when inserting into database

'Undefined index' When trying to upload photo?

Undefined offset trying to echo data from database

Error when trying to display the number of pages in PdfKit

Undefined index when trying to get information from a 2nd page

Undefined index in php when trying to output the subcategories of each category from a phpmyadmin table

Trying to insert image into database. Getting Notice: Undefined index

Undefined index for checkboxes generated from Database

having error when trying to catch values from database and display it in a text view. android

Having an issue with a null exception on WPF DataGrid when trying to display data from a database with Linq

Why do I get an error (Notice: Undefined index) when I try to echo a value from my database?

Display number of duplicates from database [SQL]

Undefined variable X issue when trying to display value on laravel blade

Undefined index error when trying to echo input text in PHP?

Doctrine: Undefined index when trying to access one-to-many php

Undefined error when trying to access Array value of Map by index

Getting "undefined" when trying to post with EXPRESS on SQL database?

Error when trying to retrieve from database

Getting Undefined variable while trying to retrieve user data from database

undefined index for database field

undefined index error when submitting form and inserting values into database?

Trying to display numbers with commas while fetching it from database