我想刪除我的html表中的字段。當我點擊刪除按鈕時,我將用戶重定向到一個彈出窗口,詢問他們是否確定是否要刪除表格中的那一行。一旦他們點擊yes,它會將它們帶到一個delete.php文件中,該文件將它從我們的數據庫中刪除。我不知道如何將這個值發送到我們的delete.php文件。發送表數據彈出刪除
<!-- /.row -->
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-body">
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover" id="dataTables-example">
<thead>
<tr>
<th>User Name</th>
<th>Distinct Items</th>
<th>Total Occurrences</th>
<th>Last Occurrence</th>
<th>Environment</th>
<th>Control</th>
</tr>
</thead>
<tbody>
<?php
include ("config.php");
$sql = "SELECT * FROM newTable";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
echo '<tr>';
echo '<td>'. $row['account_id'] . '</td>';
echo '<td>'. $row['user'] . '</td>';
echo '<td>'. $row['pass'] . '</td>';
echo '<td>'. $row['privs'] . '</td>';
echo '<td>'. $row['privValue'] . '</td>';
echo '<td>';
echo '<a href="#Modal_modify" class="btn btn-primary btn-xs" data-toggle="modal"><i class="fa fa-pencil"></i></a>';
echo '<a href="#Modal_delete" class="btn btn-danger btn-xs" data-toggle="modal"><i class="fa fa-trash-o "></i></a>';
echo '</td>';
echo '</tr>';
}
?>
<!-- Modal_delete HTML -->
<div id="Modal_delete" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Delete User</h4>
</div>
<div class="modal-body">
<p>Are you sure you want to delete this user?</p>
</div>
<form action="delete_user.php" method="post">
<input type="hidden" name="id" value="<?php echo $id;?>"/>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-danger">Delete</button>
</div>
</form>
</div>
</div>
</div>
問題是創建刪除按鈕我引用一個html子例程來創建一個被點擊的彈出窗口。我如何將表格數據發送到我的delete.php文件?
<?php
include ("test.php");
$tbl_name="newTable"; // Table name
$id = $_POST['id'];
echo $_POST['id'];
echo "$id";
// To protect MySQL injection (more detail about MySQL injection)
$sql="DELETE FROM tbl_name WHERE account_id='$id';";
mysql_query(sql);
header("Location: adminUser.php");
?>
好感謝輸入所以我應該使用jQuery來獲取價值。我怎麼會真的把它發送到我的PHP文件? – user3404290 2014-08-31 05:23:49
您只需提交表格,就像您今天所做的那樣。 '$ _POST [「id」]'將從隱藏的輸入'name ='id''中獲得新的值。你可以從id輸入中刪除'value =「<?php echo $ id;?>」'。 – 2014-08-31 23:40:58
嗯我加了你說的,價值還沒有通過 – user3404290 2014-09-01 00:15:28