I'm trying to select and delete multiple rows in my table, using php. Whenever I select check multiple rows to make my deletion, I get this error "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'id 5' at line 1". I am able to delete single rows, when I check my checkbox, individually. here is a snippet to my code:
<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("mydatabase") or die(mysql_error());
if (isset($_GET['delete'])){
$multiple = $_GET['multiple'];
$i = 0;
$sql = "DELETE FROM product ";
foreach ($multiple as $item_id) { $i ++;
if ($i == 1){
$sql .= " WHERE id = " . mysql_real_escape_string($item_id) . "";
} else{
$sql .= "OR id ". mysql_real_escape_string($item_id) . "";
}
}
mysql_query($sql) or die(mysql_error());
header("location: " . $_SERVER['PHP_SELF']);
exit();
}
?>