Jump to content


Photo

Unknown column 'male' in 'where clause'


  • Please log in to reply
2 replies to this topic

#1 brokeDUstudent

brokeDUstudent
  • Members
  • Pip
  • Newbie
  • 2 posts
  • LocationPhiladelphia

Posted 09 October 2003 - 04:10 AM

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.

#2 shivabharat

shivabharat
  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 09 October 2003 - 05:15 AM

Try this

<?php
$search = mysql_query(\"SELECT fname, lname, email FROM users WHERE gender = \'$gender\'\") or die (mysql_error());
$result = mysql_fetch_row($search);
?>
Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks

#3 brokeDUstudent

brokeDUstudent
  • Members
  • Pip
  • Newbie
  • 2 posts
  • LocationPhiladelphia

Posted 10 October 2003 - 02:45 AM

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!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users