Jump to content

PHP MySQL Query Issue


zebe

Recommended Posts

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 = 1
EXPORT 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]
Link to comment
https://forums.phpfreaks.com/topic/16232-php-mysql-query-issue/
Share on other sites

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...
Link to comment
https://forums.phpfreaks.com/topic/16232-php-mysql-query-issue/#findComment-67255
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.