Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 2nd, 2004, 03:41 PM
Authorized User
 
Join Date: Jun 2003
Location: San Jose, CA, USA.
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default Weird MySQL error

Ok, what am I doing wrong here:

Code:
SELECT * FROM ocs_tracker WHERE date > '1080892800' AND date < '1080979199' AND user in (cmiller,dharrington,jmockabee) ORDER BY idnum ASC
results in this error:

Code:
1054 - Unknown column 'cmiller' in 'where clause'
Am I missing something, because I have this running just fine in another script (on a different machine).

Thanks in advance for the help.


----------
~cmiller
__________________
----------
~cmiller
 
Old April 3rd, 2004, 11:41 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Single quotes around your values in the list, maybe?

Either that, or your machine may be using some ancient version of mysqld that doesn't support IN.
 
Old April 5th, 2004, 05:15 PM
Authorized User
 
Join Date: Jun 2003
Location: San Jose, CA, USA.
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, that works... So putting single quotes around the items in the IN clause gets a result, however that variable is being generated from an implode from an array, so I don't have a lot of control over the output. Any other suggestions?

Here's what I'm trying to accomplish:
I am running a report on employee time. You select the employees that you want to include in the report by checking checkboxes next to their names. <input type=text name="empid[]" value="cmiller">, then from within the PHP you: $emp_list = implode(",", $empid); and then run the query... SELECT * FROM blah WHERE user IN ('$empid');

Anyone got an suggestions?

----------
~cmiller
 
Old April 6th, 2004, 04:08 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Just off the top of my head....

 $emp_list = implode("','", $empid);
$emp_list = "'" . $emp_list . "'";

It's an ugly kludge, but I think it'll work.

Unless you quote the values, MySQL thinks it's being passed a column names, as your first error indicated.




Similar Threads
Thread Thread Starter Forum Replies Last Post
Weird Error Message jeremy1048 Access 2 April 8th, 2008 04:52 AM
Weird Syntax Error mjhoagland Classic ASP Professional 3 May 5th, 2007 04:25 AM
VWD Weird Error bmains Visual Studio 2005 1 May 2nd, 2005 09:46 AM
Weird Combobox Error kpowers@wppisys.org ADO.NET 0 October 1st, 2003 10:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.