Jump to content

SELECT....WHERE.....IN - unknown column in 'where' clause


RLJ

Recommended Posts

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!

 

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

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.