RLJ Posted February 21, 2011 Share Posted February 21, 2011 Hi all, I have the following code, and it's not working, and I can't work out why not: $transcheck = $_POST['transcheck']; //is an array $IDs = implode (',',$transcheck); echo $IDs; $link = mysql_connect ('localhost', 'root'); if (!$link) {die('Could not connect: ' . mysql_error());} $selectDB = mysql_select_db ('database', $link); if (!$selectDB) {die('Could not select database: ' . mysql_error());} $result= mysql_query (" SELECT email FROM sometable WHERE ID IN(".$IDs.") "); if (!$result) {die('Could not search database: ' . mysql_error());} I get the following error message: Unknown column 'c5a2bca6' in 'where clause' where c5a2bca6 is one of the IDs from $transcheck. if it's any help, the echo statement gives $IDs as: c5a2bca6,493f6710,87004d13 Help pls! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/228441-selectwherein-unknown-column-in-where-clause/ Share on other sites More sharing options...
kickstart Posted February 21, 2011 Share Posted February 21, 2011 Hi That is a string so needs quotes within the IN clause. Change the following 2 lines as below and that should fix it. $IDs = implode ("','",$transcheck); SELECT email FROM sometable WHERE ID IN('".$IDs."') All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/228441-selectwherein-unknown-column-in-where-clause/#findComment-1177923 Share on other sites More sharing options...
RLJ Posted February 21, 2011 Author Share Posted February 21, 2011 Thanks Keith! Quote Link to comment https://forums.phpfreaks.com/topic/228441-selectwherein-unknown-column-in-where-clause/#findComment-1177927 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.