我有以下下拉列表
index.php (我相信错误,看不到,错误报告已开启)
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<title></title>
<script type="text/javascript">
function ajaxFunction(choice)
{
var httpxml;
try
{
// Firefox, Opera 8.0+, Safari
httpxml=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
httpxml=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
httpxml=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
function productChanged()
{
if(httpxml.readyproduct==4)
{
//alert(httpxml.responseText);
var myObject = JSON.parse(httpxml.responseText);
for(j=document.myForm.product.options.length-1;j>=0;j--)
{
document.myForm.product.remove(j);
}
var `=myObject.value.product1;
var optn = document.createElement("OPTION");
optn.text = 'Select product';
optn.value = '';
document.myForm.product.options.add(optn);
for (i=0;i<myObject.product.length;i++)
{
var optn = document.createElement("OPTION");
optn.text = myObject.product[i];
optn.value = myObject.product[i];
document.myForm.product.options.add(optn);
if(optn.value==product1){
var k= i+1;
document.myForm.product.options[k].selected=true;
}
}
//////////////////////////
for(j=document.myForm.employee.options.length-1;j>=0;j--)
{
document.myForm.employee.remove(j);
}
var employee1=myObject.value.employee1;
//alert(employee1);
for (i=0;i<myObject.employee.length;i++)
{
var optn = document.createElement("OPTION");
optn.text = myObject.employee[i];
optn.value = myObject.employee[i];
document.myForm.employee.options.add(optn);
if(optn.value==employee1){
document.myForm.employee.options[i].selected=true;
}
}
///////////////////////////
document.getElementById("txtHint").style.background='#00f040';
document.getElementById("txtHint").innerHTML='done';
//setTimeout("document.getElementById('txtHint').style.display='none'",3000)
}
}
var url="check.php";
var category=myForm.category.value;
if(choice != 's1'){
var product=myForm.product.value;
var employee=myForm.employee.value;
}else{
var product='';
var employee='';
}
url=url+"?categories="+categories;
url=url+"&products="+products;
url=url+"&employees="+employees;
url=url+"&id="+Math.random();
myForm.st.value=product;
//alert(url);
document.getElementById("txtHint2").innerHTML=url;
httpxml.onreadyproductchange=productChanged;
httpxml.open("GET",url,true);
httpxml.send(null);
document.getElementById("txtHint").innerHTML="Please Wait....";
document.getElementById("txtHint").style.background='#f1f1f1';
}
</script>
</head>
<body >
<?php
require 'connect-db.php';
session_start();
$session_id=session_id(uniqid());
?>
</head>
<body>
<div id="txtHint" style="width : 100px;background-color: #cccc33;"></div>
<br><br>
<form name="myForm" action='details.php' method='post'>
<input type=hidden name=st value=0>
<table width=500>
<tr><td >
Select category<br><select name=category id='s1' onchange=ajaxFunction('s1');>
<option value=''>Select One</option>
<?Php
$select_category="SELECT DISTINCT categories FROM products ";
foreach ($dbo->query($select_category) as $row) {
echo "<option value=$row[categories]>$row[categories]</option>";
}
?>
</select>
</td><td ><select name=product onchange=ajaxFunction('s2');>
<option value=''>Select Product</option></select></td>
<td ><select name=employee onchange=ajaxFunction('s3');>
<option value=''>Select Employee</option></select></td>
</tr></tr>
<tr><td colspan=3><input type=submit value='Submit'></td></tr>
</form>
</table>
<br><br>
<div id="txtHint2"></div>
</body>
</html>
details.php
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<title></title>
</head>
<body>
<?Php
echo "category : $_POST[categories]<br>
product : $_POST[products]<br>
employee : $_POST[employee]<br>
<br><br><br>
Return to <a href=index.php>Drop down list</a>
";
?>
</body>
</html>
check.php
<?Php
require "connect-db.php"; // connection details
$category=$_GET['categories'];
$product1=$_GET['products'];
$employee1=$_GET['employees'];
;
///////////// Validate the inputs ////////////
// Checking category variable ///
if((strlen($category)) > 0 and (!ctype_alpha($category))){
echo "Data Error";
exit;
}
// Checking product variable (with space ) ///
if ((strlen($product1)) > 0 and ctype_alpha(str_replace(' ', '', $product1)) === false) {
echo "Data Error";
exit;
}
/////////// end of input validation //////
if(strlen($category) > 0){
$q_category="SELECT DISTINCT(name) FROM products WHERE categories = '$category'";
}else{
$q_category="SELECT DISTINCT(name) FROM products";
}
//echo $q_category;
$sth = $dbo->prepare($q_category);
$sth->execute();
$product = $sth->fetchAll(PDO::FETCH_COLUMN);
$q_product="SELECT DISTINCT(fname,lname) FROM employees ";
if(strlen($category) > 0){
$q_product= $q_product . " categories = '$category' ";
}
if(strlen($product1) > 0){$q_product= $q_product . " and products='$product1'";}
$sth = $dbo->prepare($q_product);
$sth->execute();
$employee = $sth->fetchAll(PDO::FETCH_COLUMN);
$main = array('products'=>$products,'employees'=>$employee,'value'=>array("product1"=>"$product1","employee1"=>"$employee1"));
echo json_encode($main);
////////////End of script /////////////////////////////////////////////////////////////////////////////////
?>
所以错误很简单,我有一个名为products的表,包含类别,我只是不能在下拉菜单中列出它们,我知道这可能是我的一个愚蠢的错误,它是凌晨3点所以有点盲目。我发布了整个剧本,如果还有其他我没见过的问题,我很乐意了解它们。