Reputation: 23
I have a checkbox form which passes an array of id values. I then implode the array like this:
$ship = $_POST['result'];
$array=implode(",", $ship);
$shipping=ship_update($array);
The Mysql query function looks like this:
function ship_update($array){
global $MEMS;
echo $array;
$query="SELECT * FROM Inventory
WHERE MEMS_ID IN ('$array')
ORDER BY WAFER ASC, RC ASC";
$shipping=$MEMS -> exec($query);
return $shipping;
}
When I run this code, $shipping returns an empty query. What am I doing wrong?
Upvotes: 0
Views: 1197
Reputation: 64466
Try your query without '
single quotes
SELECT * FROM Inventory
WHERE MEMS_ID IN ($array)
ORDER BY WAFER ASC, RC ASC
Upvotes: 1
Reputation: 263683
This should be
$array = "'" . implode("','", $ship) . "'";
And in your query,
$query="SELECT * FROM Inventory
WHERE MEMS_ID IN ($array) // remove the single quotes to
ORDER BY WAFER ASC, RC ASC"; // avoid syntax error
warning, this is still vulnerable with sql injection.
Upvotes: 2
Reputation: 23001
There aren't any single quotes in the middle of your array. Change
$array=implode(",", $ship);
to
$array=implode("','", $ship);
Upvotes: 0