Good night folks,

I have written this code a zillion times and tonight it is not working. I need a fresh pair of eyes to have a look and let me know what I am doing wrong.

I am trying to create a link to result retrieved from a database. Basically the first page returns entries in a library and I am creating a link on the author to see all the books in the library written by that person. I am wrapping the author field in a URL which includes $_GET but it does not seem to be working.

Please have a look at http://www.library.bcd.org.bb/biblio.php. I have the code displayed there.

I am using PHP 5.2.5 and MySQL 5.0.45. Register Globals is set to "on".

Thanks in advance ....

Terry

I can click on the Author and it displays a set of books that they have authored.

Is this problem now resolved?

I can click on the Author and it displays a set of books that they have authored.

Is this problem now resolved?

Hi Alex,

Yes and no. I found a roundabout route. The code at lines 67 & 70 (below) will not parse the data retrieved from the database so what I did was to replace $_GET[author] with $row[author] and pass it in that form to the author.php page where the superglobal in the SELECT statement correctly receives the $row[author] value.

Since posting I changed the page and that's why you do get the list now. However, I am still at a loss as to what I did wrong. The original code is below. If you can please take a look at that for me and let me know where I went wrong, I would appreciate it.

Cheers
Terry

<?php
// Addresses error handling
ini_set('display_errors',1);
error_reporting (E_ALL & ~E_NOTICE);
?>

<html>
<head>
<title>Bibliography Reference Library</title>
<style type="text/css">
td.results {style="border-style:none; padding: 5px"}
p.dashed {border-bottom-style: dashed; border-bottom-width: thin; padding-top: 1cm; padding-top: 1cm}
</style>
</head>
<body>


 <?php

    // Handle the form
    if (isset($_GET['submit'])) {

    require_once ('/home/barbados/private/mysql_connect.php'); // Connect to the database.


    $searchstring = mysql_escape_string($_GET['words']);

        $sql = "SELECT id, title, author, coauthor, category, format, publisher, datepub, pubplace, edition, loan, notes, image,
               MATCH(title, author, coauthor, publisher)
               AGAINST ('$searchstring' IN BOOLEAN MODE) FROM books
               WHERE MATCH(title, author, coauthor, publisher)
               AGAINST ('$searchstring' IN BOOLEAN MODE) ORDER BY title DESC";
        if ($result = mysql_query($sql)) // if there are records, do the following

        {

            echo '<table><tr>';
            echo '<td class="results" valign="top"width="300">Results for <b><i>'.$searchstring.' </i></b></td>';
            echo '<td class="results"><form method="get" action="">';
            echo '<input type="hidden" name="boolean" value="search" />';
            echo '<input type="text" name="words" value="'.$searchwords.'" />&nbsp;';
            echo '<input type="submit" name="submit" value="Search" />';
            echo '</form></td>';
            echo '</tr></table>';



            while($row = mysql_fetch_array($result))

            {

                echo '<div class="Text10"><div id="FullTextHighlight">';

                      // Thumbnail
                      if (empty($row[image]))
                      { echo '<img src="/images/no-image.jpg" align="left" hspace="10" alt="'.stripslashes(htmlspecialchars($row[title])).' "><br />';}
                      else
                      {
                        echo '<img src="/images/'.stripslashes(htmlspecialchars($row[image])). '" align="left"  hspace="10" alt="'.stripslashes(htmlspecialchars($row[title])).'"><br />';
                      }

                echo '<strong>Title:</strong> ['.$row[id].'] ' .stripslashes(htmlspecialchars($row[title])).' ('. $row[edition].') <i> by ';


                      // Author and co-author
                      if (empty($row[coauthor]))
                      { echo '<a href="author.php?author='.$_GET[author].'">'.stripslashes(htmlspecialchars($row[author])).'</a></i><br />';}
                      else
                      {
                        echo '<a href="author.php?author='."$_GET[author]".'">'.stripslashes(htmlspecialchars($row[author])).'</a> ,&nbsp; '.stripslashes(htmlspecialchars($row[coauthor])).'</i><br />';
                      }


                      // Publisher
                      if (empty($row[publisher]))
                      { echo ' '; }
                      else
                      { echo '<strong>Published by:</strong> '.$row[publisher].' '.$row[datepub].' '.$row[pubplace].'<br />';}


                      // Format
                      if (empty($row[format]))
                      { echo '';}
                      else
                      {
                      { echo stripslashes(htmlspecialchars($row[format])).'<br />';}
                      }


                      // Description
                      if (empty($row[notes]))
                      { echo ' '; }
                      else
                      { echo '<strong>Additional information:</strong> '.$row[notes].'<br />';}





                echo '<strong>Available for lending?</strong>&nbsp;'.$row[loan].'<br />';


                echo '</div><p class="dashed" /></p>';

echo '<hr>';



            }

        } else {

            echo '<b>Oops!</b> You searched for <b>'.$searchstring.' </b>but it does not exists. Please try again';

            }

        echo '<div align="center">';
        echo '<h2><i>New Search</i></h2>';

        echo '<form method="get" action="">';
        echo '<input type="hidden" name="boolean" value="search" />';
        echo '<input type="text" name="words" value="'.$searchwords.'" />&nbsp;';
        echo '<input type="submit" name="submit" value="Search" />';
        echo '</form>';
        echo '</div>';


    } else { //Make form
    $searchwords = (isset($_GET['words']) ? htmlspecialchars(stripslashes($_REQUEST['words'])) : '');

    echo "<h1>Reference books and audio books</h1>";
    echo "<h3>Search by title, author, or publisher</h3>";

        echo '<form method="get" action="">';
        echo '<input type="hidden" name="boolean" value="search" />';
        echo 'Search for: <input type="text" name="words" value="'.$searchwords.'" />&nbsp;';
        echo '<input type="submit" name="submit" value="Search" />';
        echo '</form>';

    }

show_source('biblio.php');

I would have possibly wrote your get code as:

$_GET['author']

Other than that I can't see a problem

I would have possibly wrote your get code as:

$_GET['author']

Other than that I can't see a problem

Thanks Alex. I have used that same syntax many times before and on this occasion it just won't budge and I have no idea why not.


Cheers
Terry

This article has been dead for over six months. Start a new discussion instead.