I recently did a ZAP report on my project, and there was a high alert saying SQL Injection may be possible through Foldable' AND '1'='1' attack on this particular drop-down menu 'bsearch'. I would like to know if it is possible to solve this issue through Prepared Statement and how do I do it? Thank you.
This is my SQL (PHP)
$filter = "";
if(isset($_POST['bsearch']))
{
$mod_selected = $_POST['bsearch'];
$filter = " WHERE catename ='$mod_selected'";
}
$conn = mysqli_connect('localhost','root','','my_db');
$productsql = "SELECT DISTINCT catename FROM catetable";
$model_list = mysqli_query($conn,$productsql);
mysqli_close($conn);
And this the drop-down menu form.
<section class = "content feature">
<section id="featurepage">
<article id="featurenav">
<h1>
Category
</h1>
<form name = "bikeoption" id = "bikeoption" method = "post">
<p id = "searchlabel">
Select Bike Category:
</p>
<select name="bsearch" id="bsearch">
<?php while ($one_model= mysqli_fetch_assoc($model_list) ) { ?>
<option value="<?php echo $one_model['catename']; ?>">
<?php echo $one_model['catename']; ?>
</option>
<?php } ?>
</select>
<input type="submit" value = "Search" id = "bsearchBtn" class = "button">
</form>
<br>