gpt4 book ai didi

php - 编辑用户模式不起作用 :?

转载 作者:行者123 更新时间:2023-11-30 21:47:40 25 4
gpt4 key购买 nike

所以我正在尝试创建一个模式,它将从显示的表格中编辑用户(选定)。

我已经尝试了 2 种不同类型的提交来让这个过程工作,但首先是我的 PHP 代码..(是的,清理变量,它很快就会被添加)

if ($_POST['edituser']) {
$uid = strip_tags($_POST['edituser']);
if (isset($_POST['email'])) {
$newemail = $_POST['email'];
mysqli_query($con, "UPDATE `users` SET `email` = '$newemail' WHERE `uid` = '$uid'") or die(mysqli_error($con));
}
if (isset($_POST['usergroup'])) {
$newusergroup = $_POST['usergroup'];
mysqli_query($con, "UPDATE `users` SET `usergroup` = '$newusergroup' WHERE `uid` = '$uid'") or die(mysqli_error($con));
}
if (isset($_POST['paypal'])) {
$newpaypal = $_POST['paypal'];
mysqli_query($con, "UPDATE `users` SET `paypal` = '$newpaypal' WHERE `uid` = '$uid'") or die(mysqli_error($con));
}
if (isset($_POST['avatarlink'])) {
$newavatarlink = $_POST['avatarlink'];
mysqli_query($con, "UPDATE `users` SET `avatarlink` = '$newavatarlink' WHERE `uid` = '$uid'") or die(mysqli_error($con));
}
if (isset($_POST['job'])) {
$newjob = $_POST['job'];
mysqli_query($con, "UPDATE `users` SET `job` = '$newjob' WHERE `uid` = '$uid'") or die(mysqli_error($con));
}
if (isset($_POST['aboutme'])) {
$aboutme = $_POST['aboutme'];
mysqli_query($con, "UPDATE `users` SET `aboutme` = '$newaboutme' WHERE `uid` = '$uid'") or die(mysqli_error($con));
}
header("Location: /staff/users?success=true");
die();
}

现在这些是我尝试过的两种提交方法...

1 -

<?php
$ug = $userRow['usergroup'];
$result = mysqli_query($con, "SELECT * FROM `users`") or die(mysqli_error($con));
while ($row = mysqli_fetch_array($result)) {
echo '
<div id="editUser'.$row['uid'].'" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Edit User</h4>
</div>
<form method="POST" action="users">
<div class="modal-body">
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="username" class="control-label">Username</label>
<input type="text" class="form-control" readonly="" id="username" value="'.$row['username'].'" disabled>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="email" class="control-label">Email</label>
<input type="text" class="form-control" name="email" id="email" value="'.$row['email'].'">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="usergroup" class="control-label">Usergroup</label>';
if ($ug == "Owner" || $ug == "Manager") {
echo '<select name="usergroup" class="form-control">
<option value="'.$row['usergroup'].'" selected="selected" disabled>'.$row['usergroup'].'</option>
<option value="Client">Client</option>
<option value="Freelancer">Freelancer</option>
<option value="Moderator">Moderator</option>
<option value="Manager">Manager</option>
<option value="Owner" disabled>Owner</option>
</select>';
} else {
echo '<input type="text" class="form-control" readonly="" id="usergroup" value="'.$row['usergroup'].'" disabled>';
}echo '
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="paypal" class="control-label">PayPal</label>';
if ($ug == "Owner" || $ug == "Manager") {
echo '<input type="text" class="form-control" name="paypal" id="paypal" value="'.$row['paypal'].'">';
} else {
echo '<input type="text" class="form-control" readonly="" id="paypal" value="'.$row['paypal'].'" disabled>';
}echo '
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="joindate" class="control-label">Join Date</label>
<input type="text" class="form-control" readonly="" id="joindate" value="'.$row['joindate'].'" disabled>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="joinip" class="control-label">Join IP</label>
<input type="text" class="form-control" readonly="" id="joinip" value="'.$row['joinip'].'" disabled>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="avatarlink" class="control-label">Avatar Link</label>
<input type="text" class="form-control" name="avatarlink" id="avatarlink" value="'.$row['avatarlink'].'">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="job" class="control-label">Job / Skills</label>
<input type="text" class="form-control" name="job" id="job" value="'.$row['job'].'">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="aboutme" class="control-label">About</label>
<input type="text" class="form-control" name="aboutme" id="aboutme" value="'.$row['aboutme'].'">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="portfolio_link" class="control-label">Portfolio</label>
<input type="text" class="form-control" name="portfolio_link" id="portfolio_link" value="'.$row['portfolio_link'].'">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="tos" class="control-label">Accepted TOS</label>
<input type="text" class="form-control" readonly="" id="tos" value="'.$row['tos_accepted'].'" disabled>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-danger btn-block" name="edituser">Edit User</button>
</div>
</form>
</div>
</div>
</div>
'; }
?>

使用这种方法(如上),没有任何反应...页面只是刷新。

2

<?php
$ug = $userRow['usergroup'];
$result = mysqli_query($con, "SELECT * FROM `users`") or die(mysqli_error($con));
while ($row = mysqli_fetch_array($result)) {
echo '
<div id="editUser'.$row['uid'].'" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Edit User</h4>
</div>
<form method="POST" action="users">
<div class="modal-body">
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="username" class="control-label">Username</label>
<input type="text" class="form-control" readonly="" id="username" value="'.$row['username'].'" disabled>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="email" class="control-label">Email</label>
<input type="text" class="form-control" name="email" id="email" value="'.$row['email'].'">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="usergroup" class="control-label">Usergroup</label>';
if ($ug == "Owner" || $ug == "Manager") {
echo '<select name="usergroup" class="form-control">
<option value="'.$row['usergroup'].'" selected="selected" disabled>'.$row['usergroup'].'</option>
<option value="Client">Client</option>
<option value="Freelancer">Freelancer</option>
<option value="Moderator">Moderator</option>
<option value="Manager">Manager</option>
<option value="Owner" disabled>Owner</option>
</select>';
} else {
echo '<input type="text" class="form-control" readonly="" id="usergroup" value="'.$row['usergroup'].'" disabled>';
}echo '
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="paypal" class="control-label">PayPal</label>';
if ($ug == "Owner" || $ug == "Manager") {
echo '<input type="text" class="form-control" name="paypal" id="paypal" value="'.$row['paypal'].'">';
} else {
echo '<input type="text" class="form-control" readonly="" id="paypal" value="'.$row['paypal'].'" disabled>';
}echo '
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="joindate" class="control-label">Join Date</label>
<input type="text" class="form-control" readonly="" id="joindate" value="'.$row['joindate'].'" disabled>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="joinip" class="control-label">Join IP</label>
<input type="text" class="form-control" readonly="" id="joinip" value="'.$row['joinip'].'" disabled>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="avatarlink" class="control-label">Avatar Link</label>
<input type="text" class="form-control" name="avatarlink" id="avatarlink" value="'.$row['avatarlink'].'">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="job" class="control-label">Job / Skills</label>
<input type="text" class="form-control" name="job" id="job" value="'.$row['job'].'">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="aboutme" class="control-label">About</label>
<input type="text" class="form-control" name="aboutme" id="aboutme" value="'.$row['aboutme'].'">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="portfolio_link" class="control-label">Portfolio</label>
<input type="text" class="form-control" name="portfolio_link" id="portfolio_link" value="'.$row['portfolio_link'].'">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="tos" class="control-label">Accepted TOS</label>
<input type="text" class="form-control" readonly="" id="tos" value="'.$row['tos_accepted'].'" disabled>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<input type="submit" name="edituser" class="btn btn-danger btn-block" value="Edit User">
</div>
</form>
</div>
</div>
</div>
'; }
?>

尝试使用此方法(如上)时,页面和通知显示......但数据库中没有任何更新。

感谢您的帮助:)

最佳答案

如评论中所述,您的代码目前非常不安全。你绝对应该使用 parametrised queries以防止人们破坏您的数据库,以及 protect yourself from xss attacks以防止您的网站成为恶意软件。

不过,您的问题的答案是给您的输入字段一个 name attribute in addition to an id .

现在,您的表单没有发布任何数据 - 因此没有任何更改。

关于php - 编辑用户模式不起作用 :?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48694164/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com