Superadmin = "admin">Admin = "mod-6ren">
gpt4 book ai didi

php - <选择> 和 $_POST

转载 作者:行者123 更新时间:2023-11-29 08:18:40 25 4
gpt4 key购买 nike

我想编辑一个拥有用户名、密码和权限的管理员。最后一个是这样制作的:

<?php $showQuery = mysqli_query($db, "SELECT * FROM admins WHERE id = {$id}"); 
$show = mysqli_fetch_assoc($showQuery); ?>

<p>Power:&nbsp; <select name = "power">
<option value <?php if ($show['power']=='superadmin') {echo " selected";} ?> = "superadmin">Superadmin</option>
<option value <?php if ($show['power']=='admin') {echo " selected";} ?> = "admin">Admin</option>
<option value <?php if ($show['power']=='moderator') {echo " selected";} ?> = "moderator">Moderator</option>
</select><br /><br />

然后我想捕获这些值:

<?php if (isset($_POST['editAdmin'])) {

$username = $_POST['username'];
if (!$_POST['password'] == "") { $password = $_POST['password']; }
$power = $_POST['power'];

$editQuery = "UPDATE admins SET ";
$editQuery .= "username = '{$username}', ";
if (isset($password)) { $editQuery .= "hashed_pwd = '{$password}', "; }
$editQuery .= "power = '{$power}' ";
$editQuery .= "WHERE id = {$id} LIMIT 1";

$editAdmin = mysqli_query($db, $editQuery);

现在,如果我不想更改管理员的权限(保持选项不变)并点击“编辑”,则权限将变为空白。但是,如果我更改电源(升级或降级),则设置正常。我做错了什么?

最佳答案

您错误地构造了您的选择,您的选项设置如下:

<option value <?php if ($show['power']=='admin') {echo " selected";} ?> = "admin">Admin</option>

它们应该是这样的:

<option value="admin" <?php if ($show['power']=='admin') {echo " selected";} ?> >Admin</option>

关于php - <选择> 和 $_POST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20018049/

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