【发布时间】:2021-05-09 16:01:56
【问题描述】:
我想在我的选择标签中选择后实现,它会在我的模态中显示一个输入标签,并且已经在数据库的其他表中获取。
totalfees.php
if(isset($_POST["year"]))
{
$output = '';
$query = "SELECT total_fees FROM manage_fees WHERE year_lvl = '".$_POST["year"]."'";
$result = mysqli_query($connect, $query);
while($row = mysqli_fetch_array($result))
{
$output .= '
<input type="text" class="form-control" id="tf" name="tf" readonly="readonly" value="'.$row["total_fees"].'">
';
}
echo $output;
}
gettotal.js
$(document).ready(function(){
$('#year').click(function(){
var year = $(this).attr("year");
$.ajax({
url:"../include/assessment.php",
method:"post",
data:{year:year},
success:function(data){
$('#total_fees').html(data);
}
});
});
assessment.php
<div class="modal fade" id="fee_modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Assess Student</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form method="POST" action="officer_studentAssessment.php" id="reg">
<div class="form-group">
<label for="year">Year</label>
<select class="form-control" id="year" name="year" required>
<?php
$result = $connect->query("SELECT * FROM year_lvl") or die($connect->error());
while($row = $result->fetch_assoc()):
?>
<option value="<?php echo $row['year']; ?>"><?php echo $row["year"]; ?></option>
<?php endwhile; ?>
</select>
</div>
<div class="form-group" id="total_fees">
<label for="tf">Total fees</label>
</div>
<div class="modal-footer">
<button class="btn btn-success" name="create" id="create" type="submit">Create</button>
</div>
</form>
</div>
</div>
</div>
</div>
在totalfees.php中,输出应该显示在id = total_fees的DIV标签上,问题是我点击选择标签后DIV消失了
<div class="form-group" id="total_fees">
<label for="tf">Total fees</label>
</div>
【问题讨论】:
-
警告:您对SQL Injections 持开放态度,应该使用参数化的prepared statements,而不是手动构建查询。它们由PDO 或MySQLi 提供。永远不要相信任何形式的输入!即使您的查询仅由受信任的用户执行,you are still in risk of corrupting your data。 Escaping is not enough!
-
嗨,
$(this).attr("year")应该是$(this).val()。 -
@Swati 在选择标签中选择后仍然没有显示新的 div 标签
-
你试过下面的答案了吗?
-
嘿@JanbresGagaracruz - 跟进。你的问题得到了满意的回答吗?如果我们可以提供更多帮助,请在任何答案下方添加评论,或编辑您的问题以澄清您还想知道什么。 否则,请选择“最佳答案”(通过单击答案旁边的复选标记)来结束问题。如果没有答案提供有用的信息,请添加您自己的答案并选择它作为最佳答案(关闭问题)。也请记住:您可以投票任何您认为有帮助的答案(如果需要,您也可以投票并勾选相同的答案。)*谢谢!