So I have a basic database of books set up. I am trying to use PHP to query the db and send back the results. I can sort of get it to work, but not working how I would like. The issue is that the search term that queries the db has to match the cell contents exactly. I'm going to paste both the form and the php:
<div class="bookSearch">
<form action="book_search.php" method="post">
<span id="spryBookSearch">
<input type="text" size="50" name="author" />
<span class="textfieldMaxCharsMsg">Exceeded maximum number of characters.</span></span><br />
<span id="sprytitle">
<input type="text" size="50" name="title" />
<span class="textfieldMaxCharsMsg">Exceeded maximum number of characters.</span></span><br />
<span id="spryyear">
<input type="text" name="year" />
<span class="textfieldMaxCharsMsg">Exceeded maximum number of characters.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span><br />
<span id="spryISBN">
<input type="text" name="isbn" />
<span class="textfieldMaxCharsMsg">Exceeded maximum number of characters.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span><br />
<input type="submit" name="submit" value="Submit" />
</form>
</div>
<?php
require_once 'trinity_database_login.php';
$db_server = mysql_connect($db_hostname, $db_username, $db_password);
if (!$db_server) die("Unable to connect to MySQL: " . mysql_error());
mysql_select_db($db_database, $db_server) or die("Unable to select database: " . mysql_error());
?>
<pre><table><tr>
<th>Author</th>
<th>Title</th>
<th>Year</th>
<th>ISBN</th>
</tr></pre>
<?php
if (isset($_POST['submit'])) {
$query = " ";
$author = $_POST['author'];
$title = $_POST['title'];
$year = $_POST['year'];
$isbn = $_POST['isbn'];
$query = "SELECT * FROM classics WHERE author='$author' OR title='$title' OR year='$year' OR isbn='$isbn'";
$result = mysql_query($query);
$num=mysql_numrows($result);
$i = 0;
while ($i < $num) {
$f1 = mysql_result($result, $i, "author");
$f2 = mysql_result($result, $i, "title");
$f3 = mysql_result($result, $i, "year");
$f4 = mysql_result($result, $i, "isbn");
?>
<tr>
<td><?php echo $f1; ?></td>
<td><?php echo $f2; ?></td>
<td><?php echo $f3; ?></td>
<td><?php echo $f4; ?></td>
</tr>
</table>
<?php
$i++;
}
}
mysql_close($db_server);
?>
So, for example, if I search for "Mark Twain", I get back the the author, title, year of pub and ISBN. That's all good. But if I search for just "Mark" or just "Twain", I get nothing. I took most of this code from here: http://www.siteground.com/tutorials/php-mysql/display_table_data.htm (I'm not advertising anything, just letting you know one of my resources).
Anyone see the where I can fix things? I know there is a LIKE qualifier that can be used on the command line, but obviously the web doesn't offer access to the command line.