Jump to content

Search Validation


phpanon

Recommended Posts

Hello there,

 

I have a search function on my webpage that allows users to search a keyword then select the category from a dropdown menu.

This works fine, but at the moment say the user were to enter the keyword which didnt match the category then an "unable to run query" error message will appear!?

Is there anyway of catching this error and returning no fields.... or showing the user an error message saying the search could not run

Here is my search code

if (($_GET['text'] == "") || ($_GET['field'] == "*"))	
{
	$query = "SELECT * FROM product WHERE active ='y' ORDER BY $orderby LIMIT $offset, $limit";
}
else
{
	$query = "SELECT * FROM product WHERE active ='y' AND ".$_GET['field']." like '%".$_GET['text']."%' ORDER BY $orderby";
}
$result = mysql_query($query, $connection) or die ("Unable to perform query $query");

 

And...

<form method="get" action="StationaryMain.php" name="search">
<table width="44%" border="0">
  <tr>
    <td width="33%"> </td>
    <td width="67%"><div align="center">Search  Keyword:</div></td>
    </tr>
  <tr>
    <td> </td>
    <td><input name="text" type="text" id="text" /></td>
  </tr>
  <tr>
    <td> </td>
    <td><div align="center">Select fields to search</div></td>
    </tr>
  <tr>
    <td> </td>
    <td><div align="center">
      <select name="field" id="field">
        <option value="*">Choose category</option>
        <option value="URN">URN</option>
        <option value="productName">Product Name</option>
        <option value="productType">Product Type</option>
        <option value="description">Description</option>
        <option value="price">Price</option>
      </select>
    </div></td>
  </tr>
  <tr>
    <td> </td>
    <td><div align="center">
      <input name="search" type="submit" id="search" value="Search" />
    </div></td>
    </tr>
</table>
</form>

 

Thanking you in advance

Link to comment
https://forums.phpfreaks.com/topic/97717-search-validation/
Share on other sites

Archived

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

×
×
  • Create New...

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.