I have list of categories in my database that I populate in dropdown menu. The website should be able to display items depending on which category selected by user.
My current coding :
if ($selected_cat == "All Item" || !isset($selected_cat)) {
$sql_select = "SELECT * FROM tblproduct";
}
else {
$sql_select = "SELECT * FROM tblproduct WHERE prodCat = '$selected_cat'";
}
$result = $conn->query($sql_select);
if ($result->num_rows > 0){
while($row = mysqli_fetch_assoc($result))
{
extract($row);
// some statement to display item
}
}
So the problem here is, some of my category's value
have apostrophic (') such as Woman's Fashion
. If I run my query, mysql wouldn't be able to find the specific category as it read Woman's Fashion
as Woman\'s Fashion, but my query $sql_select = "SELECT * FROM tblproduct WHERE prodCat = '$selected_cat'";
is reading it as Woman's Fashion which is wrong format in mysql.