我正在尝试将多个值传递给 javascript 函数“get2”,然后调用“data2.php”文件,以便根据下拉列表/文本框中提交的值从数据库中检索数据。两者分开工作但不能一起工作,我得到的错误是“未定义的索引”。任何人都可以帮助我吗?
<script type="text/javascript">
function get2() {
$.post('data2.php', { gender: form2.gender.value },
function(output) {
$('#gender').html(output).show();
}
);
$.post('data2.php', { skills: form2.skills.value },
function(output) {
$('#skills').html(output).show();
});
}
</script>
...
...
<form name="form2">
<Select name="gender">
<OPTION>Male</OPTION>
<OPTION>Female</OPTION></SELECT>
What is the patients relationship status?
(hold "Ctrl" key to select multiple options at one time):
<br/><br/>
<BR>
<BR>
<select name="skills">
<OPTION value="Single" selected="selected">Single</OPTION>
<OPTION value="With partner">With partner</OPTION>
<OPTION value="Separated from partner">Separated from partner</OPTION>
<OPTION value="Partner died">Partner died</OPTION>
<OPTION value="DK">DK</OPTION>
</select>
<BR>
<BR>
<INPUT TYPE="button" VALUE="search" onClick="get2();">
</form>
<div id="gender"></div>
<div id="skills"></div>
DATA2.PHP
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("grist");
$gender = $_POST['gender'];
$skills = $_POST['skills'];
if (($gender==NULL) && ($skills==NULL)) {
echo"please enter gender and skills!";
}
else
{
$dob4 = mysql_query("SELECT * FROM patients WHERE gender='$gender' AND relationship_status='$skills'");
//$dob_num_rows = mysql_num_rows($dob);
while($row4 = mysql_fetch_array($dob4)){
$a=$row4['patient_id'];
$b=$row4['gender'];
$c=$row4['dob'];
echo "<b>Patient:</b> $a";
echo "<b>Patient:</b> $b";
echo "<b>Patient:</b> $c";
}
}
?>