【发布时间】:2020-03-10 14:15:55
【问题描述】:
我正在尝试将数据输出到我的模式,但没有出现。我设法在我创建的表上输出了一些数据。但是,当尝试通过模态显示更多数据时,似乎什么也没有出现。
我一直在通过 PHP 寻找可能的修复,但没有运气。
下面的 php 旨在从我的news.php 文件接收到信息后将数据输出到模态:
<?php
if(isset($_POST["employee_id"]))
{
$output = '';
$connect = mysqli_connect("localhost", "root", "test1234", "news_db");
$query = "SELECT * FROM latest_news WHERE news_id = '".$_POST["employee_id"]."'";
$result = mysqli_query($connect, $query);
$output .= '
<div class="table-responsive">
<table class="table table-bordered">';
while($row = mysqli_fetch_array($result))
{
$output .= '
<tr>
<td width="30%"><label>Name</label></td>
<td width="70%">'.$row["news_title"].'</td>
</tr>
<tr>
<td width="30%"><label>Address</label></td>
<td width="70%">'.$row["news_text"].'</td>
</tr>
';
}
$output .= "</table></div>";
echo $output;
}
?>
我的 news.php 文件中的这个表成功地从我的表中输出了所需的数据:
<div class="table-responsive">
<table class="table table-bordered">
<tr>
<th width="70%">Employee Name</th>
<th width="30%">View</th>
</tr>
<?php
while($row = mysqli_fetch_array($result)){
?>
<tr>
<td><?php echo $row["news_title"]; ?></td>
<td><input type="button" name="view" value="view" id="<?php echo $row["news_id"]; ?>" class="btn btn-info btn-xs view_data" /></td>
</tr>
<?php
}
?>
</table>
</div>
<div id="dataModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Employee Details</h4>
</div>
<div class="modal-body" id="employee_detail"></div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
模态脚本:
<script>
$(document).ready(function(){
$('.view_data').click(function(){
var employee_id = $(this).attr("news_id");
$.ajax({
url:"select.php",
method:"post",
data:{employee_id:employee_id},
success:function(data){
$('#employee_detail').html(data);
$('#dataModal').modal("show");
}
});
});
});
</script>
【问题讨论】:
-
不显示数据是您最不必担心的,您应该首先研究如何防止 SQl 注入..
-
我已经在缓解的事情,因为不需要用户输入而变得更简单@RaymondNijland
-
您的代码易受 SQL 注入攻击。您应该使用准备好的语句。
标签: javascript php mysql phpmyadmin