Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 管理员工具/更新其他用户详细信息_Php - Fatal编程技术网

Php 管理员工具/更新其他用户详细信息

Php 管理员工具/更新其他用户详细信息,php,Php,我已经实现了一个功能性的登录并注册到一个网站模板中,但我一直在研究如何使用表单样式更新数据库中的其他用户详细信息 例如,更改他们的权限组,然后mod可以为标准用户提供24小时的聊天/评论时间,等等 下面是我所说的一个非常基本的内容,它使用现有的代码完成了一个不同的表单,它获取输入的用户名,需要作为编辑行的“id” 我意识到我的代码没有需要的东西,但如果有人能给我指出正确的方向,我会非常感激 <?php require 'core/init.php'; include 'includes/o

我已经实现了一个功能性的登录并注册到一个网站模板中,但我一直在研究如何使用表单样式更新数据库中的其他用户详细信息

例如,更改他们的权限组,然后mod可以为标准用户提供24小时的聊天/评论时间,等等

下面是我所说的一个非常基本的内容,它使用现有的代码完成了一个不同的表单,它获取输入的用户名,需要作为编辑行的“id”

我意识到我的代码没有需要的东西,但如果有人能给我指出正确的方向,我会非常感激

<?php
require 'core/init.php';
include 'includes/overall/header.php';

if(!$user->hasPermission('admin')) {
    Redirect::to ('index.php');
}

if(Input::exists()) {
    if(Token::check(Input::get('token'))) {
        $validate = new Validate();
        $validation = $validate->check($_POST, array(
            'username' => array(
                'required' => true)
        ));

        if($validation->passed()) {

            try {
                $user->update(array(
                    'grouptest' => Input::get('group')
                ));
            } catch(Exception $e) {
                die($e->getMessage());
            }

            Session::flash('home', 'Your Name has been updated succssfully!.');
            Redirect::to('useraccount.php');

        } else {
            foreach($validate->errors() as $error) {
                echo $error, '<br>';
            }
        }
    }
}

?>


<form method="post" action="">
    <label for="username">Change user:</label>
    <input type="text" name="username" id="username" value=""/>
    <label for="group"> to group:</label>
    <select name="group" id="group">
        <option value="1">Standard user</option>
        <option value="2">Moderator</option>
        <option value="3">Administrator</option>
    </select>
    <input type="submit" value="Update">
</form>

更改用户:
分组:
标准用户
调解人
管理员

我整理好了,谢谢。这里是整个重写的代码只是为了这个

它是基本的,但它是自己制作的

<?php
error_reporting(E_ALL);
require 'connect.php';
require 'security.php';


$records =array();

if(!empty($_POST)){
    if(isset($_POST['username'], $_POST['perms'])){
        $username  = trim($_POST['username']);
        $perms = trim($_POST['perms']);

        if(!empty($username) && !empty($perms)){

        $update = $db->query("UPDATE users2 SET perms = '$perms' WHERE username = '$username'");

            if($update){
                echo 'success';
                header('location: updatedb.php');
                die();
            } else {
                echo 'failed';
            }
        }
    }
}
if($results = $db->query("SELECT * FROM users2")){
    if($results->num_rows){
        while($row = $results->fetch_object()){
            $records[] = $row;
        }
        $results->free();
    }
}

?>
<!DOCTYPE html>
<html>
    <head>
        <title>updatedb</title>
    </head>
        <div id="nav">
            <ul>
                <li><a href="addtodb.php">Add to DB Form</a></li>
                <li><a href="giveadmin.php">Give Admin to Admin</a></li>
                <li><a href="updatedb.php">Update DB Form</a></li>
                <li><a href="deletedb.php">Delete from DB form</a></li>
            </ul>
        </div>
    <body>
        <h3>update database</h3>

        <?php
        if(!count($records)){
            echo 'no records';
        }else{
        ?>
            <table>
                <thead>
                    <tr>
                        <th>Username</th>
                        <th>Permission level</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    foreach ($records as $r){
                    ?>
                        <tr>
                            <td><?php echo escape($r->username); ?></td>
                            <td><?php echo escape($r->perms); ?></td>
                        </tr>
                    <?php
                    }
                    ?>
                </tbody>
            </table>
        <?php
        }
        ?>
        <hr>

        <form method="post" action="">
            <label for="username">Username:</label>
            <input type="text" name="username" id="username" value=""/>
            <label for="perms">Role:</label>
            <select name="perms" id="perms">
                <option value="1">Standard user</option>
                <option value="2">Moderator</option>
                <option value="3">Administrator</option>
            </select>
            <input type="submit" value="Update">
            <input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
        </form>

    </body>
</html>
做一个
echo';var_dump($user);退出就在您的包含和发布结果之后。