URL: http://www.whatsthatmovie.com//resources/views/index.blade.php

Currently have a page that shows 3 checkboxes - SKYTV, NOWTV and BBC iPLAYER. When you click the checkbox and slide the timer, the images update of what is available - based on SQL and JSON/AJAX request.

However, sometimes this doesn't seem to update without moving the slider up and down. Sometimes this works, sometimes it doesn't. As you can see, when you test. Error logs are:

[05-May-2019 19:49:52 UTC] PHP Warning:  in_array() expects parameter 2 to be array, null given in /home2/whatstp6/public_html/resources/views/submit.php on line 28

[05-May-2019 19:52:04 UTC] PHP Warning:  in_array() expects parameter 2 to be 
array, null given in /home2/whatstp6/public_html/resources/views/submit.php on line 20

[05-May-2019 19:52:04 UTC] PHP Warning:  in_array() expects parameter 2 to be array, null given in /home2/whatstp6/public_html/resources/views/submit.php on 
line 24

[05-May-2019 19:52:04 UTC] PHP Warning:  in_array() expects parameter 2 to be array, null given in /home2/whatstp6/public_html/resources/views/submit.php on  
line 28

The line numbers 20, 24 and 28 correspond to the InArray IF STATEMENTS on submit.php (see below)

Slider on main page:

<div>
<input type="checkbox" id="nowtv" name="nowtv" >
<label for="nowtv">Now TV</label>
</div>

<div>
<input type="checkbox" id="skytv" name="skytv" >
<label for="skytv">Sky Movies</label>
</div>

<div>
<input type="checkbox" id="iplayer" name="iplayer" >
<label for="iplayer">BBC iPlayer</label>
</div>

Maximum Runtime:
<div class="slidecontainer">
<input type="range" min="0" max="200" value="0" class="slider" id="runtime">
<p>Runtime: <span id="runtime_"></span></p>
</div>

Code on main page for AJAX (please excuse that it says Employer, I was following a tutorial).

function getEmployeeFilterOptions(){
// here we're creating an object instead of an array#
var opts = {
checkboxes: [],
sliderValue: null
};
$checkboxes.each(function(){
if(this.checked){
opts.checkboxes.push(this.name);
}
});
var slider = document.getElementById("runtime");
opts.sliderValue = slider.value;
return opts;
}
function updateEmployees(opts){
$.ajax({
type: "POST",
url: "submit.php",
dataType : 'json',
cache: false,
data: opts,
success: function(records){
console.log(records);
$('#employees tbody').html(makeTable(records));
}
});
}

var $checkboxes = $("input");
$checkboxes.on("change", function(){
var opts = getEmployeeFilterOptions();
updateEmployees(opts);
});
</script>

Submit.php code:

$checkboxes = $_POST["checkboxes"];
$slider_value = $_POST["sliderValue"];

$select = 'SELECT *';
$from = ' FROM streaming';
$where = ' WHERE poster <>"" AND runtime < ? AND (channel = "X" ';

if (in_array("nowtv", $checkboxes))
{
$where .= ' OR channel = "NOWTV" ';
}
if (in_array("skytv", $checkboxes))
{
$where .= ' OR channel = "SKYTV" '; 
}
if (in_array("iplayer", $checkboxes))
{
$where .= ' OR channel = "BBC" '; 
}


$where .= ' ) '; 
$sql = $select . $from . $where;
$statement = $pdo->prepare($sql);

$statement->execute([$slider_value]);

$results = $statement->fetchAll(PDO::FETCH_ASSOC);
$json = json_encode($results);
echo($json);

I expected the table to be updated when the checkboxes are ticked and when the slider is moved.

0 Answers