Getting Query Failed and not sure why...
Hi,
I'm adding a search functionality to a newly created service request
database. I copied over pretty much all of the code from a previous,
currently working, inventory tracking database that I created. I
changed the field names and whether I wanted "LIKE" or =, but still,
all I get is a query failed message.
Can someone help please!!!
Query code is as follows:
$query = mysql_query("SELECT * FROM support
WHERE (first LIKE '%$searchfor%' OR last LIKE '%$searchfor%' OR
priority LIKE '%$searchfor%' OR inventory='$searchfor' OR owner LIKE '%
$searchfor%' OR building LIKE '%$searchfor%' OR room='$searchfor' OR
email LIKE '%$searchfor%' OR phone LIKE '%$searchfor%' OR issue LIKE '%
$searchfor%' OR c_id LIKE '%$searchfor%')",$db) or die ("Query
failed");
$numofrows = mysql_num_rows($query);
Re: Getting Query Failed and not sure why...
Sloane T. Irwin wrote:
> Hi,
> I'm adding a search functionality to a newly created service request
> database. I copied over pretty much all of the code from a previous,
> currently working, inventory tracking database that I created. I
> changed the field names and whether I wanted "LIKE" or =, but still,
> all I get is a query failed message.
>
> Can someone help please!!!
>
> Query code is as follows:
Try this:
$thequery="SELECT * FROM support
WHERE (first LIKE '%$searchfor%' OR last LIKE '%$searchfor%' OR
priority LIKE '%$searchfor%' OR inventory='$searchfor' OR owner LIKE '%
$searchfor%' OR building LIKE '%$searchfor%' OR room='$searchfor' OR
email LIKE '%$searchfor%' OR phone LIKE '%$searchfor%' OR issue LIKE '%
$searchfor%' OR c_id LIKE '%$searchfor%')";
$query = mysql_query($thequery,$db);
if(!$query) {
echo $thequery ."<br>\n";
echo mysql_errno().": ".mysql_error()."<br>\n";
exit;
}
$numofrows = mysql_num_rows($query);
This way you get a lot better error information than using those "or die()"
statements. You want to see what query has been made and what error message.
--
//Aho