[英]How can I get data from this HTML to query in SQL?
This is the button used to send the data 这是用于发送数据的按钮
<a href="#myModal" data-toggle="modal" id="78" data-target="#edit-modal"> <button type="button" >
<i class="glyphicon glyphicon-zoom-in"></i>
</button></a>
This code shows the data 此代码显示数据
<?php echo $er="<div class=\"modal-body edit-content\"></div>"; ?>
I want $er
to query in below 我想在下面查询$er
<?php
$str = "SELECT * FROM examquestion WHERE EQ_ID = '$er' ";
$Recordset7 = mysql_query($str) or die(mysql_error());
$row_Recordset7 = mysql_fetch_assoc($Recordset7);
echo $row_Recordset7['EQ_ID']; ?>
script 脚本
<script>
$('#edit-modal').on('show.bs.modal', function(e) {
var $modal = $(this),
Id = e.relatedTarget.id;
$modal.find('.edit-content').html(Id);
})
</script>
You can do it by using AJAX. 您可以使用AJAX来完成。 Learn these: 了解这些:
http://www.w3schools.com/ajax/ http://www.w3schools.com/ajax/
http://php.net/manual/en/mysqli.quickstart.prepared-statements.php http://php.net/manual/en/mysqli.quickstart.prepared-statements.php
Prepared statements will save you from SQL Injection attacks. 准备好的语句将使您免受SQL Injection攻击。 Practice to use it specially if you're doing a query that has an input from user. 如果要查询的是来自用户的输入,请练习专门使用它。
HTML HTML
<a href="#myModal" data-toggle="modal" id="78" class='get-content' data-target="#edit-modal">
<button type="button">
<i class="glyphicon glyphicon-zoom-in"></i>
</button>
</a>
<div id="edit-modal">
<div class="modal-body edit-content"></div>
</div>
PHP (content.php) Using procedural mysql PHP(content.php)使用过程mysql
<?php
$er = $_POST['id'];
$str = "SELECT * FROM examquestion WHERE EQ_ID = '$er' ";
$Recordset7 = mysql_query($str) or die(mysql_error());
$row_Recordset7 = mysql_fetch_assoc($Recordset7);
echo $row_Recordset7['EQ_ID'];
?>
PHP Using OOP mysqli (prepared statement) PHP使用OOP mysqli(准备好的语句)
$mysqli = new mysqli("localhost", "user", "password", "database");
$query = "SELECT content FROM examquestion WHERE EQ_ID = ?";
if ( $stmt = $mysqli->prepare($query) )
{
$stmt->bind_param("s", $er);
if ( $stmt->execute() )
{
$stmt->bind_result($content);
while ($stmt->fetch()) {
echo $content;
}
}
$stmt->close();
}
JS JS
<script>
$('a.get-content').click(function() {
var contentId = $(this).attr('id');
var modalId = $(this).attr('data-target');
$.ajax({
url: "content.php",
type: "POST",
data: {id: contentId},
dataType: "html",
success:function(data){
$(modalId).find('.edit-content').eq(0).html(data);
}
});
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.