Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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
Reply With Quote
  #2 (permalink)  
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.
Reply With Quote
  #3 (permalink)  
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
Reply With Quote
  #4 (permalink)  
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.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 02:44 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.