zebe Posted August 1, 2006 Share Posted August 1, 2006 Hi,I'm trying to run a query like the following example:[code]$activity = $HTTP_POST_VARS["activity"];$sql = "SELECT first, last, email FROM student_involvement WHERE " . $activity . " = 1"; $result = mysql_query($sql) or die(mysql_error()); [/code]The variable $activity is pulling a column name from a predefined select list of activities. Each one of these fields is an int field and if it is true it will have a 1 false a 0. The query fails:SELECT first, last, email FROM student_involvement WHERE acapella = 1EXPORT ERROR:Unknown column 'acapella' in 'where clause'Does anyone know why this is failing? The columns exist, I can pull general data from that table, but it seems to throw errors when I try to implement a WHERE clause...Thanks for all of your help in advance![b][/b] Quote Link to comment Share on other sites More sharing options...
HeyRay2 Posted August 1, 2006 Share Posted August 1, 2006 Does hardcoding the column name work?[code=php:0]$sql = "SELECT first, last, email FROM student_involvement WHERE acapella = 1"; [/code]Let us know if the query is successful. Quote Link to comment Share on other sites More sharing options...
zebe Posted August 1, 2006 Author Share Posted August 1, 2006 Just hardcoded it as requested and that is throwing the same error as well... Not sure what's up. The table exists and the columns do as well... Quote Link to comment Share on other sites More sharing options...
Caesar Posted August 1, 2006 Share Posted August 1, 2006 Yeah...paste this before your query & let us know if it works:[code]<?php$query = mysql_query("SELECT * FROM student_involvement WHERE acapella ='1'");$res = mysql_fetch_array($query);print_r($res);exit;?>[/code] Quote Link to comment Share on other sites More sharing options...
zebe Posted August 1, 2006 Author Share Posted August 1, 2006 I get a blank page... Quote Link to comment Share on other sites More sharing options...
Caesar Posted August 1, 2006 Share Posted August 1, 2006 Then the array is blank. It's not retrieving anything from that field in the table. Mind pasting a screenshot of that table? Quote Link to comment Share on other sites More sharing options...
zebe Posted August 1, 2006 Author Share Posted August 1, 2006 Screenshot is attached[attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
Caesar Posted August 1, 2006 Share Posted August 1, 2006 Though the field/column is there....is there any data in it yet? Quote Link to comment Share on other sites More sharing options...
zebe Posted August 1, 2006 Author Share Posted August 1, 2006 Yes,I have a form that was placing data into the fields. If a user checked that activity it would store a 1 in the respective field, 0 otherwise. All the int fields are storing are basic binary true false data from checkboxes. When I browse, those fields have 0's and 1's in them, so there is data in there... Quote Link to comment Share on other sites More sharing options...
king arthur Posted August 1, 2006 Share Posted August 1, 2006 This table is definitely named "student_involvement"? Quote Link to comment Share on other sites More sharing options...
zebe Posted August 1, 2006 Author Share Posted August 1, 2006 Yes it is called student_involvement. I can extract first name last name etc fine, but the problem arises when I try to do a where clause on the integer fields... Quote Link to comment Share on other sites More sharing options...
Caesar Posted August 1, 2006 Share Posted August 1, 2006 If you convert the field to varchar, and then run the script again...what are the results? I asume if you add the WHERE clause criteria using a field that is an integer but also set as a primary key, it won't return the error? Quote Link to comment Share on other sites More sharing options...
zebe Posted August 1, 2006 Author Share Posted August 1, 2006 Changed the `acapella` column to a varchar(1) type, ran it again and got the same unknown column in where clause error... Quote Link to comment Share on other sites More sharing options...
Caesar Posted August 1, 2006 Share Posted August 1, 2006 If you would like (Because I'm very damned curious :-P) send me an email and I will give you my AIM sn & I can help troubleshoot this for you. :) (sammyone@gmail.com) Quote Link to comment Share on other sites More sharing options...
ryanlwh Posted August 1, 2006 Share Posted August 1, 2006 are you connecting to a different database from php that has this table but without the acapella column? Quote Link to comment Share on other sites More sharing options...
Caesar Posted August 1, 2006 Share Posted August 1, 2006 [quote author=ryanlwh link=topic=102606.msg407510#msg407510 date=1154462590]are you connecting to a different database from php that has this table but without the acapella column?[/quote]True dat. Check to make sure you're not doing that. Quote Link to comment 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.