Jump to content

Archived

This topic is now archived and is closed to further replies.

xiledweb

Search query finds all results instead of categories

Recommended Posts

So, I have a database with sports related articles, and I'm having problems with users running a specific search.

The user can search by author, category and 'containing text'. Despite that, it returns all articles listed in the database.

Another, nay, several pair of eyes would be appreciated.

[code]
$authors = @mysql_query('SELECT id, name FROM author');
if (!$authors) {
  exit('<p>Unable to obtain author list from the database.</p>');
}

$cats = @mysql_query('SELECT id, name FROM category');
if (!$cats) {
  exit('<p>Unable to obtain category list from the database.</p>');
}
?>

<form action="articlelist.php" method="post">
<p>View articles satisfying the following criteria:</p>
<label>By author:
<select name="aid" size="1">
  <option selected value="">Any Author</option>
<?php
while ($author = mysql_fetch_array($authors)) {
  $aid = $author['id'];
  $aname = htmlspecialchars($author['name']);
  echo "<option value='$aid'>$aname</option>\n";
}
?>
</select></label><br />
<label>By category:
<select name="cid" size="1">
  <option selected value="">Any Category</option>
<?php
while ($cat = mysql_fetch_array($cats)) {
  $cid = $cat['id'];
  $cname = htmlspecialchars($cat['name']);
  echo "<option value='$cid'>$cname</option>\n";
}
?>
</select></label><br />
<label>Containing text: <input type="text" name="searchtext" /></label><br />
<input type="submit" value="Search" />
</form>
[/code]

Share this post


Link to post
Share on other sites
You have no 'WHERE' clause in your SQL queries...

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.