This question already has an answer here:
Ok, I have searched numerous topics on this and now I am stuck.
I am trying to write a query that will pull data from a MySQL database using PHP code. The query is based on user input from a form. I would like the user to input any keyword and return all the corresponding data from all tables in the entire database. It is a textbook database and I would like the user to be able to search based on Title, Price, Edition, Date, or ISBN.
<?php
$query= $_GET['query'];
$result = mysql_query("SELECT * FROM `thetextbookexpress` WHERE (`Author(s)` LIKE '%.".$query."%')
OR (`Title` LIKE '%.".$query."%')
OR (`Price` LIKE '%.".$query."%')
OR (`Edition` LIKE '%.".$query."%')
OR (`ISBN-13` LIKE '%".$query."%')
OR (`ISBN-10` LIKE '%.".$query."%') OR (`ISBN-13` LIKE '%.".$query."%')");
$num = mysql_numrows($result);
echo "<table id='search' border='1'>
<tr>
<tr>
<th>Author(s)</th>
<th>Title</th>
<th>Price</th>
<th>Edition</th>
<th>Date</th>
<th>ISBN-10</th>
<th>ISBN-13</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['Author(s)'] . "</td>";
echo "<td>" . $row['Title'] . "</td>";
echo "<td>" . $row['Price'] . "</td>";
echo "<td>" . $row['Edition'] . "</td>";
echo "<td>" . $row['Publication Date'] . "</td>";
echo "<td>" . $row['ISBN-10'] . "</td>";
echo "<td>" . $row['ISBN-13'] . "</td>";
}
?>
Edit: I have fixed the error thanks to you! It was a simple mistake of a wrong column in the query. Although, now I have a new problem as I now see a blank page when a keyword is entered in the form. Here is additional code for the form and button.
<form action="search.php" method="get">
<input type="text" name="query" alt="Search Books" value=" Search by ISBN, Author, or Title"
maxlength="356" size="52";/>
<input type="submit" name="querybtn" value="Search Books"/>
</div>
You have an error on your query put a
die(mysql_error());
before mysql_fetch_array to see where is the error exactly in your query..
And then maybe I could help you
MySQL returns resource on success, FALSE on error. Use mysql_error() to see whats happening.