warstormer Posted August 6, 2007 Share Posted August 6, 2007 Hi, I'm getting a: Unknown column 'DW' in 'where clause' error, where DW is passed in a query string 'products.php?prodid=DW' and turned into the variable $prodid_query. The actual query is: $result = mysql_query("select * from products_tbl WHERE prod_id = $prodid_query LIMIT 0, 30 ") or die(mysql_error()); The table field 'prod_id' is set as varchar. The strange thing is if I alter the data and use '01' as the $prodid_query variable it works fine... Quote Link to comment https://forums.phpfreaks.com/topic/63563-solved-unknown-column-variable-in-where-clause/ Share on other sites More sharing options...
wildteen88 Posted August 6, 2007 Share Posted August 6, 2007 wrap $prodid_query with in quotes: $result = mysql_query("select * from products_tbl WHERE prod_id = '$prodid_query' LIMIT 0, 30 ") or die(mysql_error()); MySQL will treat the value of $prodid_query as a column name and not a string. Quote Link to comment https://forums.phpfreaks.com/topic/63563-solved-unknown-column-variable-in-where-clause/#findComment-316771 Share on other sites More sharing options...
warstormer Posted August 6, 2007 Author Share Posted August 6, 2007 wrap $prodid_query with in quotes: $result = mysql_query("select * from products_tbl WHERE prod_id = '$prodid_query' LIMIT 0, 30 ") or die(mysql_error()); MySQL will treat the value of $prodid_query as a column name and not a string. so simple, and of course works.... Thanks for the help! Quote Link to comment https://forums.phpfreaks.com/topic/63563-solved-unknown-column-variable-in-where-clause/#findComment-316774 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.