Possible Duplicate:
How to prevent SQL injection in PHP?
I have this code
$where = '';
if (isset($_POST['lvl']) && $vals = $_POST['lvl']) {
$where = 'WHERE ';
$first = false;
if ($vals[0] === '0') {
$where .= 'team = "neutral"';
unset($vals[0]);
$first = true;
}
if (count($vals)) {
if ($first) $where .= ' OR ';
$where .= 'lvl IN (\'' . implode('\',\'', $vals) . '\')';
}}
$sql = "SELECT * FROM $table $where";
$res = $DBH->prepare($sql);
$res->execute();
$num = $res->rowCount();
echo "<h2>".$num."</h2>";
It works, but if someone did something, then this happens. How to fix this?
UPD: added PDO code