Let me see if I can explain what's happening...
So I've got a PHP page where results from a specific search are displayed. In this page I've got select boxes (this particular one is static) to filter my results, in this case specifically, by region. This region_id value is being passed through Ajax/Jquery.
$("#region").change(function(){
var region_id = $(this).val();
console.log(region_id);
$.ajax({
url:"results2.php",
method:"POST",
data: {region_id:region_id},
success: function(data){
$("#filter_results").html(data);
}
});
})
This PHP page "results2" also receives through HTML GET 2 attributes (recipeid and recipename). One is used in the SQL query, the other is purely for dynamic display. Everything runs smoothly but whenever I start applying filters "recipeid" and "recipename" this message appears:
Notice: Undefined index: recipeid in... Notice: Undefined index: recipename in...
However, the filters are being correctly applied, but the results are wrong since those 2 variables are not being taken into account.
Here's the part of my PHP where results are shown (sql query included)...
<?php
$recipeid = $_GET["recipeid"];
$recipename = $_GET["recipename"];
$servername = "localhost";
$username = "root";
$password = "";
$db = "motherwine";
// Create connection
$conn = new mysqli($servername, $username, $password, $db);
$conn->set_charset("utf8");
// Check connection
if ($conn->connect_error) {
die("Erro: " . $conn->connect_error);
}
//Display results with region filter ON
if (isset($_POST["region_id"])) {
if($_POST["region_id"] !="")
{ $region_id = implode("", $_POST["region_id"]);
$sql="SELECT wineid, wine_name, winetype_name, wine_img, region_name, sponsored, recipe_name, recipeid, grade_name, nota
FROM (SELECT wine.id AS wineid, wine_name, winetype_name, wine_img, region_name, sponsored, recipe_name, recipe.id AS recipeid, round(avg(grade_id),0) AS nota
FROM wine, winetype, region, recipe, rating, pairing
WHERE wine.id = pairing.wine_id AND wine.winetype_id = winetype.id AND wine.region_id = region.id AND
recipe.id = pairing.recipe_id AND
rating.pairing_id = pairing.id and recipe.id LIKE '%$recipeid%' and wine.region_id LIKE '$region_id'
GROUP BY wineid, wine_name, recipe_name) AS temp, grade
WHERE grade.id = temp.nota ORDER BY sponsored DESC, nota DESC;";
$result = $conn->query($sql);
echo '<div class="container">
<div class="row justify-content-start text-left mb-2">
<div class="col-md-9" data-aos="fade">
<h2 class="font-weight-bold text-black">Para acompanhar "'.$recipename.'", a mãe sugere...</h2>
</div>
</div>
<div class="row justify-content-end text-right">
<h6 class="pr-4 text-black">Ordenar por:</h6>
<div class="single-element-widget">
<div class="default-select" id="default-select">
<select>
<option value="1">Avaliação: melhor</option>
<option value="1">Avaliação: pior</option>
<option value="1">Preço: mais caro</option>
<option value="1">Preço: mais barato</option>
</select>
</div>
</div>
</div>
<div class="row" data-aos="fade">';
If there's not enough information please let me know...