Jump to content

Error matching field data


spmckee

Recommended Posts

Greetings,

 

I have a data field in mySQL that reads "Fish and Shellfish", when I try to match it with the same string I get this error:

Error in query: SELECT `cat_id` FROM `categories` WHERE `cat_name` = Fish and Shellfish. Unknown column 'Fish' in 'where clause

 

Basically it breaks when it hits the whitespace in the field data. Any ideas?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/97444-error-matching-field-data/
Share on other sites

oops, also you will prbably need to do something like this instead:

 

SELECT `cat_id` FROM `categories` WHERE `cat_name` = 'Fish' OR `cat_name` = 'Shellfish'

 

or you could even:

 

SELECT `cat_id` FROM `categories` WHERE `cat_name` LIKE '%fish%'

 

(i believe most mysql installations are case sensitive, you need to change the mysql character table to make it insensitive)

 

hope this helps,

Thanks for the swift reply but I think it will make it clearer if I include the whole piece. This is part of a function:

function get_cat_id($which_one){
		$query = "SELECT `cat_id` FROM `categories` WHERE `cat_name` = $which_one";
		$result=mysql_query($query) or die ("Error in query: $query. " . mysql_error());
		while($row = mysql_fetch_array($result)) {$which_one=$row['cat_id'];};
		return $which_one;
	}

 

How do I translate your tips into the function?

 

Thanks again.

change

$query = "SELECT `cat_id` FROM `categories` WHERE `cat_name` = $which_one";

to

$query = "SELECT `cat_id` FROM `categories` WHERE `cat_name` = '$which_one' ";

or

$query = "SELECT `cat_id` FROM `categories` WHERE `cat_name` LIKE '%$which_one%' ";

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.