Page 1 of 1

ISBN search engine

Posted: Tue Mar 08, 2005 9:27 am
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]

Posted: Tue Mar 08, 2005 9:45 am
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.

ISBN Search Engine

Posted: Tue Mar 08, 2005 4:45 pm
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.