I tried to follow this tutorial http://www.w3schools.com/php/php_ajax_database.asp
I want to send the value from a select(with onchange) to change the sql query.
function myfunctionTime(time) {
if (time=="") {
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","book.php?id=<?php echo $FILM_ID; ?>&q="+time,true);
xmlhttp.send();
}
Here is the select with the onchange:
<p for="session">Time:</p>
<select class="form-control" id="session" name="session"onchange="myfunctionTime(this.value)">
<option selected="selected" value="12:00">12:00</option>
<option value="16:00">16:00</option>
<option value="20:00">20:00</option>
</select>
Here is the PHP where I want to get the variable.
// Print all the get variables
print_r($_GET);
// Film session or time
$session = "12:00";
$session = $_GET['q'];
echo "Session: ".$session;
$query = "SELECT * FROM booking WHERE (FILM_ID = '$film_id' AND BOOKING_SESSION = '$session')";
And this is the error I get:
Notice: Undefined index: q in C:\xampp\htdocs...\book.php on line 271