PHP AJAX and MySQL
PHP AJAX and MySQL
我试着学习本教程http://www.w3schools.com/php/php_ajax_database.asp
我想发送select中的值(使用onchange)来更改sql查询。
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();
}
以下是带有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>
这是我想要获取变量的PHP。
// 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')";
这就是我得到的错误:
注意:C:''examplep''htdocs中的未定义索引:q。。。''book.php,电话:271
将$session
值更改为此
$session = $_GET['id'];
time
为空。验证不起作用,因为它是undefined
而不是""
。因此检查CCD_ 5以进行验证。
也在函数myfunctionTime(time)
的开头检查时间值,如console.log(time);
相关文章:
- JavaScript Arrays and MySQL
- Mysql and onbeforeunload
- Interfacing html, javascript, php and mysql
- chartJs with MySQL and PHP
- filtet data by checkbox using jquery ajax mysql and php
- jQuery $.each loop and json mysql data
- jade, express, and mysql results
- module.exports scope and node-mysql
- Javascript and PHP promt for MySQL
- Working with Node and MySQL
- JavaScript, PHP and MySQL
- MySQL Security with PHP, javascript, and HTML?
- jQuery UI Autocomplete append with PHP and MySQL
- jquery autocomplete javascript, php and mysql
- Order ofQuery with AJAX PHP and MySQL
- PHP AJAX and MySQL
- Javascript, PHP and MySQL relations
- php mysql and pagination
- Slider PHP, MYSQL and JS
- javascript, php, mysql and settimeout