Jump to content

Recommended Posts

Hi All,

 

I've been working on a search page even though I was getting some GREAT advice from some of you, I've decided to start over.  The code was a complete mess and I could never really get anywhere with it on my own so ....

 

Anyway, I've rebuilt it and it seems to be working fine but it won't recognize the options selected from dropdown menus.  I get a "Unknown column in where clause" error.  I'm populating the dropdowns from arrays.

 

The search code:

$qry = "SELECT * FROM table WHERE description LIKE '%$keywords%'";

if ($_POST['location'] != '') {
    $qry .= " AND location = " . $location;	
}

$qry .= " ORDER BY ad_date DESC";

$result = mysql_query($qry) or die(mysql_error());

 

The dropdown:

<select name="location">
<?
echo "<option value=\"\">Choose A Location</option>\n";
for ($i=0;$i<count($locations);$i++) {
if ($locations[$i] == $location) {
	echo "<option value=\"$locations[$i]\" selected>$locations[$i]</option>\n";
}
else {
	echo "<option value=\"$locations[$i]\">$locations[$i]</option>\n";
}
}
?> 
</select>

 

And the locations array:

$locations = array('Boston','New London','New York');

 

And I have a "location" field in the database.  Any idea why this is happening?

Link to comment
https://forums.phpfreaks.com/topic/86814-solved-unknown-column-in-where-clause/
Share on other sites

I get a "Unknown column in where clause" error.  I'm populating the dropdowns from arrays.

 

That error means that you names your column wrong or have defined the column in your SQL query.

 

For instance the table created contains a column called "desc" but in your query you called it "description".

 

Hmmm.  Well, the exact message I'm getting is

 

Unknown column 'Boston' in 'where clause'

 

Replace 'Boston' with whichever location I select from the dropdown.

 

The database has a column titled 'location' with records within named Boston, the dropdown is named 'location' and the resulting query looks like:

 

SELECT * FROM table WHERE description LIKE '%any%' AND location = Boston ORDER BY ad_date DESC

 

I'm stumped...

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.