ISBN search engine

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vittelite
Forum Newbie
Posts: 12
Joined: Tue Mar 08, 2005 9:23 am

ISBN search engine

Post by vittelite »

Hi guys, I'm having a little trouble searching through tables that have a column labelled 'isbn', with values such as "1291849202" or "817263892X". The column is set to varchar(10), please let me know if you have any ideas. My code looks like this:

Code: Select all

<?php

$searchtype=$HTTP_POST_VARSї'searchtype'];
$searchterm=$HTTP_POST_VARSї'searchterm'];

$searchterm= trim($searchterm);

if (!$searchtype || !$searchterm)
{
echo 'You have not entered search details. Please go back and try again.';
exit;
}

$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);


$display = 10;
if (isset($_GETї'np'])) {
$num_pages = $_GETї'np'];
} else {

$query = &quote;SELECT * FROM books, course WHERE &quote;.$searchtype.&quote; like '%&quote;.$searchterm.&quote;%' AND books.isbn = course.isbn&quote;;
$query_result = mysql_query ($query);
$num_results = @mysql_num_rows($query_result);
.
.
And the search engine looks like:
<tr> 
<td>Choose Search Type: 
<select name=&quote;searchtype&quote;>
<option selected value=&quote;name&quote;>Book Title</option>
<option value=&quote;author&quote;>Author</option>
<option value=&quote;publisher&quote;>Publisher</option>
<option value=&quote;isbn&quote;>ISBN Code</option>

</select></td>
</tr>

<tr> 
<td>Enter Search Term: 
<input type=&quote;text&quote; name=&quote;searchterm&quote;></td>
</tr>

feyd | Please use

Code: Select all

tags while

Code: Select all

is offline.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

standard sql/query debugging:
  • adding 'or die(mysql_error())' to most database calls. eg.

    Code: Select all

    $result = mysql_query($query) or die(mysql_error());
  • Displaying the query being sent to the database. eg.

    Code: Select all

    $query = &quote;SELECT * FROM books, course WHERE &quote;.$searchtype.&quote; like '%&quote;.$searchterm.&quote;%' AND books.isbn = course.isbn&quote;;
    var_export($query);
    $query_result = mysql_query ($query) or die(mysql_error());
  • checking the validity of the returns from the database functions.
Last edited by feyd on Tue Mar 08, 2005 5:07 pm, edited 1 time in total.
vittelite
Forum Newbie
Posts: 12
Joined: Tue Mar 08, 2005 9:23 am

ISBN Search Engine

Post by vittelite »

Thanks feyd,
found the problem straight away after that. It was in my search engine code:
<option value="isbn">ISBN Code</option>

had to be:
<option value="book.isbn">ISBN Code</option>

I just had to state which table I had to select the ISBN column from.
Post Reply