我正在进行注册页面,其中应根据其他2个输入文本框填充一个输入文本框。
tblEntries
Id; firstname; lastname; age; gender; categories
tblCategories
Id; categories; age_from; age_to, gender
Data inserted: 1; Veteran_male; 20; 30; male
frmEntries.php is populated with tblEntries data onload already using localstorage.
(may look like this
Firstname=Peter
Lastname=Trump
Age=25
Gender=male
Categories= ?(from sql)
include("conn.php");
include("categories.php");
<input id="firstname" type="text" name="firstname" value="" />
<input id="lastname" type="text" name="lastname" value="" />
<input id="age" type="text" name="age" value="" />
<input id="gender" type="text" name="gender" value="" />
<input id="categories" type="text" name="categories" value="<?php echo $output; ?>" />
(tblCategories中的25落在20到30之间,两个表中都显示了性别)
categories.php
<php?
include ('conn.php');
$gender = $_POST["gender"];
$age = $_POST["age"];
$result = $con->query("SELECT categories FROM tblCategories WHERE '$age' BETWEEN age_from AND age_to AND gender='$gender'”);
$result = mysqli_query($con, $query);
$output = '';
while($row = mysqli_fetch_array($result))
{
$output = $row["categories"];
}
echo($output);- //(to be populated inside the frmEntries and the
“categories” field onload)
}
?>
我应该用按钮使用Ajax吗?
<script>
$('#updateBtn').click(function(e){
//to disable the click from going to next page
e.preventDefault();
$.ajax(
'categories.php', function(data){
$('#categories').val(data);
}
);
});
</script>
请告知如何执行此操作。我是否应该在onload之后使用按钮来填充“类别”?我变量找不到错误