brokeDUstudent Posted October 9, 2003 Share Posted October 9, 2003 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. Quote Link to comment https://forums.phpfreaks.com/topic/1140-unknown-column-male-in-where-clause/ Share on other sites More sharing options...
shivabharat Posted October 9, 2003 Share Posted October 9, 2003 Try this <?php $search = mysql_query(\"SELECT fname, lname, email FROM users WHERE gender = \'$gender\'\") or die (mysql_error()); $result = mysql_fetch_row($search); ?> Quote Link to comment https://forums.phpfreaks.com/topic/1140-unknown-column-male-in-where-clause/#findComment-3863 Share on other sites More sharing options...
brokeDUstudent Posted October 10, 2003 Author Share Posted October 10, 2003 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! Quote Link to comment https://forums.phpfreaks.com/topic/1140-unknown-column-male-in-where-clause/#findComment-3875 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.