Jump to content


Photo

Search query finds all results instead of categories


  • Please log in to reply
1 reply to this topic

#1 xiledweb

xiledweb
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 03 September 2006 - 03:14 AM

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.

$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>


#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 03 September 2006 - 10:26 AM

You have no 'WHERE' clause in your SQL queries...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users