我需要帮助,使用data-target="#edit<?php echo $row['user_id']; ?>"
时不会显示我的模态,但是删除<?php echo $row['user_id']; ?>
时会显示模态,但显示mysqli无法提取的错误。我需要
这是我的代码。
<div class="container" style="margin-top: 30px">
<table id="myTable" class="table table-bordered table-hover">
<thead>
<tr>
<th>Last Name</th>
<th>First Name</th>
<th>Middle Name</th>
<th>Date of Birth</th>
<th>Email</th>
<th>Contact</th>
<th>Actions</th>
</thead>
<tbody>
<?php
include_once "../config.php";
if ($link-> connect_error) {
die("Connection failed: " . $link-> connect_error);
}
$sql = "SELECT user_id, lname, fname, mname, bday, email, contact FROM users";
$result = $link-> query($sql);
if ($result-> num_rows > 0) {
while ($row = $result -> fetch_assoc()) {
echo "<tr><td>" . $row["lname"] . "</td><td>" . $row["fname"] . "</td><td>" . $row["mname"] . "</td><td>" . $row["bday"] . "</td><td>" . $row["email"] . "</td><td>" . $row["contact"] . "</td>"; ?>
<td>
<a data-placement="top" data-toggle="tooltip" title="View"><button class="btn btn-success btn-xs" data-title="View" data-toggle="modal" data-target="#view">View</button></a>
<a data-placement="top" data-toggle="tooltip" title="Edit"><button class="btn btn-info btn-xs" data-title="Edit" data-toggle="modal" data-target="#edit<?php echo $row['user_id']; ?>">Edit</button></a>
<a data-placement="top" data-toggle="tooltip" title="Delete"><button class="btn btn-danger btn-xs" data-title="Delete" data-toggle="modal" data-target="#delete">Delete</button></a>
</td>
<?php
echo "</tr>";
}
echo "</table>";
}
else {
echo "0 result";
}
$link-> close();
?>
</tbody>
</table>
</div>
<div class="modal fade" id="edit<?php echo $row['user_id']; ?>" tabindex="-1" role="dialog" aria-labelledby="edit" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button>
<h4 class="modal-title" id="Heading">Edit User Details</h4>
</div>
<div class="modal-body">
<?php
$edit=mysqli_query($conn, "select * from users where user_id='".$row['user_id']."'");
$erow=mysqli_fetch_array($edit);
?>
<form method="POST" action="edit_users.php?user_id=<?php echo $erow['user_id']; ?>">
<div class="form-group">
<p>First Name</p>
<input class="form-control " type="text" value="<?php echo $erow['fname'];?>">
</div>
<div class="form-group">
<p>Middle Name</p>
<input class="form-control " type="text" value="<?php echo $erow['mname'];?>">
</div>
<div class="form-group">
<p>Last Name</p>
<input class="form-control " type="text" value="<?php echo $erow['lname'];?>">
</div>
</div>
<div class="modal-footer ">
<button type="button" class="btn btn-warning btn-lg" style="width: 100%;"><span class="glyphicon glyphicon-ok-sign"></span>Update</button>
</div>
</div>
</div>
</div>
我的edit_users.php
<?php
include('../config.php');
$id=$_GET['user_id'];
$fname=$_POST['fname'];
$mname=$_POST['mname'];
$lname=$_POST['lname'];
$bday=$_POST['bday'];
$address=$_POST['address'];
$gender=$_POST['gender'];
$contact=$_POST['contact'];
$email=$_POST['email'];
$userlvl=$_POST['userlvl'];
mysqli_query($conn, "update users set fname='$fname', mname='$mname', lname='$lname', bday='$bday', address='$address', gender='$gender', contact='$contact', email='$email', userlvl='$userlvl' where user_id='$id'");
header('location: users.php');
?>
我是编码的新手,到目前为止,我只是从网上观看视频或代码示例,从登录到使用引导程序进行设计,然后在数据库中添加用户,到目前为止,我所遇到的一些问题已经解决了,示例是在哪一页可以重定向到该用户是管理员还是仅仅是用户,但是我现在遇到的这个问题对我来说是如此棘手,因为我仍在上学,因此我需要进行2天的上下班时间。请帮忙。