我需要帮助...我正在尝试使用PHP和模态对话框引导程序进行插入/更新/查看/删除表单。 我设法做插入过程。但无法从引导模式对话框更新,查看和删除。
db connection& process
<?php
define('host', 'localhost');
define('user', 'root');
define('password', '');
define('db_name', 'testing');
$connect = NEW mysqli(host,user,password,db_name) or die (mysqli_error());
if(isset($_POST['add']))
{
$name = $connect->real_escape_string($_POST['name']);
$email = $connect->real_escape_string($_POST['email']);
$address = $connect->real_escape_string($_POST['address']);
if($SQL)
{
?>
<script>
alert('Data Inserted!.');
window.location.href='crud.php';
</script>
<?php
}
}
if(isset($_GET['edit']))
{
$SQL = $connect->query("SELECT * FROM tbl_employee WHERE id=".$_GET['edit']);
$view= $SQL->fetch_array(MYSQLI_BOTH);
}
if(isset($_POST['update']))
{
$SQL = $connect->query("UPDATE tbl_employee SET Nama='".$_POST['name']."', Email='".$_POST['email']."', Address='".$_POST['address']."' WHERE id=".$_GET['edit']);
if($SQL)
{
?>
<script>
alert('Data Updated.');
window.location.href='crud.php';
</script>
<?php
}
}
if(isset($_GET['delete']))
{
$SQL = $connect->query("DELETE FROM tbl_employee WHERE id=".$_GET['delete']);
if($SQL)
{
?>
<script>
alert('Data Deleted!.');
window.location.href='crud.php';
</script>
<?php
}
}
?>
形式
<div id="employee_table">
<table class="table table-bordered">
<tr>
<th width=10%>#</th>
<th width=60%>Employee Name</th>
<th width=20%>Action</th>
</tr>
<?php
while($row = mysqli_fetch_array($result))
{
@$no++;
?>
<tr>
<td><?php echo $no; ?></td>
<td><?php echo $row["name"]; ?></td>
<td><?php echo $row["email"]; ?></td>
<td><?php echo $row["address"]; ?></td>
<td>
<input type="button" name="view" value="View" id="<?php echo $row["id"]; ?>" class="btn btn-info btn-xs view_data"
data-toggle="modal" data-target="#view" />
<input type="button" name="view" value="Update" id="<?php echo $row["id"]; ?>" class="btn btn-info btn-xs
update_data"
data-toggle="modal" data-target="#update" />
<input type="button" name="view" value="Delete" id="<?php echo $row["id"]; ?>" class="btn btn-info btn-xs
delete_data"
data-toggle="modal" data-target="#delete" />
</td>
</tr>
<?php
}
?>
</table>
</div>
查看模式对话框
<div id="view" 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>Employee Details</h4>
</div>
<div class="modal-body" id="employee_detail">
<form method="post" id="insert_form" action="">
<label>Employee name</label>
<input type="text" name="name" id="name" class="form-control" value="<?php if(isset($_GET['update'])){ echo $view['1']; } ?>" readonly="" />
<br>
<label>Employee Address</label>
<textarea name="address" id="address" class="form-control" value="<?php if(isset($_GET['update'])){ echo $view['2']; } ?>"readonly=""></textarea>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
答案 0 :(得分:0)
您无法像这样查看员工的详细信息。
使用ajax调用显示详细信息。
您传递在视图按钮中分配的ID ???
如果您是PHP的初学者,请查看以下链接。
它将帮助您进行CRUD操作。
演示链接:http://demos.itechempires.com/php-mysql-crud-operations/
或者使用它:
<input type="button" name="view" value="View" onclick="view_data('<?=$row['name']?>','<?=$row['address']?>')" class="btn btn-info btn-xs view_data"
data-toggle="modal" data-target="#view" />
<script type="text/javascript">
function view_data(name,address) {
$('#view input[name=name]').val(name);
$('#view input[name=address]').val(address);
}
</script>