0

SO i get data from a form using this

$LoadId=implode(',',array_filter($_POST["load"]));

I then would like to submit this to a MSSQL query with an "in" statement

where myLoadId in $LoadId

but the $LoadID looks like 7209,7210 and I need it to look like ('7209','7210')

user163169
  • 135
  • 2
  • 9
  • 2
    `where myLoadId in ($LoadId)`.. but you need to prevent sql injections so `where myLoadId in ?` would be the correct suggestion. – Lawrence Cherone Jul 16 '19 at 15:49
  • not 100% dupe - but I'd heavily recommend switching to PDO for use of prepared statements https://stackoverflow.com/questions/1586587/pdo-binding-values-for-mysql-in-statement – treyBake Jul 16 '19 at 16:03

2 Answers2

1

Seems your LoadId column contains interger value so why you need single quotes ' around it? Simply use-

$LoadId=implode(',',array_filter($_POST["load"]));
$query = "SELECT * FROM your_table WHERE myLoadId IN ($LoadId)";
echo $query;

If you still need quotes around it then you can do it this way-

$LoadId = "'".implode("','", array_filter($_POST["load"]))."'";
$query = "SELECT * FROM your_table WHERE myLoadId IN ($LoadId)";
echo $query;

WORKING DEMO: https://3v4l.org/2XEjJ

A l w a y s S u n n y
  • 36,497
  • 8
  • 60
  • 103
0

Put simple quotes around the implode() and change it's glue from , to ',' :

$LoadId = "'".implode("','", array_filter($_POST["load"]))."'";