Jump to content

Unknown column 'male' in 'where clause'


brokeDUstudent

Recommended Posts

Hey how\'s it going,

I\'m trying to do a search on a table I created that has a couple different fields in it: fname, lname, email, pword, gender, location, rent, age, year, smoker, and pets. Using PHP I am trying to let users do a search on this table through selecting values in a drop down list which then are passed to the search string. I\'ve been having problems lately.. and I think it\'s just with the gender field.

 

In the drop down list on the search.htm page in the gender box, I select Male and the value is male for that option. I hit search and it refers to search.php and I grab the variable by $gender = $_POST[\'gender\'].. then my query looks like this:

 

[php:1:58bc16ca71]<?php

$search = mysql_query(\"SELECT fname, lname, email FROM users WHERE gender = $gender\") or die (mysql_error());

$result = mysql_fetch_row($search);

?>[/php:1:58bc16ca71]

 

It returns an error and says: Unknown column \'male\' in \'where clause\' ...

I only put one record in and in the gender field it\'s value is male, I\'m just not sure why I\'m getting this error? Sorry if this should be in the PHP section.. I didn\'t know which would be better, I figured I\'d start here. Thanks for any ideas.. if you need more code or anything I\'ll be quick to post it for you.

Link to comment
Share on other sites

man.. the headache I went through, I even thought to myself that if i put the \' \'s around the variable name that it would just search for the gender called $gender .. if u know what I mean. Atleast it works.. thanks shiva, that\'s a big relief :) .. now I have to figure out how to get the output to look right when there\'s more than one row.. thanks for your help!

Link to comment
Share on other sites

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.