我需要帮助处理表格PHP / HTML的数据

时间:2022-04-02 02:05:17

I am creating a system for a website that will allow the admin of the website to accept and reject new user registrations from the admin panel.

我正在为网站创建一个系统,允许网站管理员接受并拒绝来自管理面板的新用户注册。

The table will look something like NOT the actual table, this is an example:

该表看起来不像实际的表,这是一个例子:

<th>Username</th> <th>Email</th> <th>Real Name</th> <th>Checkbox</th>
<button>Activate User</button>    <button>Delete User</button>

The checkbox is an actual checkbox in the real table.

该复选框是真实表格中的实际复选框。

When the admin logs in and goes to accept users I have an SQL command to collect all users that are not activated and shows them in the example table above.

当管理员登录并转到接受用户时,我有一个SQL命令来收集所有未激活的用户,并在上面的示例表中显示它们。

What I want to know is, using the checkbox on the table, how can I allow the admin to check the checkbox to select multiple users and then either accept them or delete them? I know the SQL command I need to use and everything else but I just don't know how to set up the table so that when the checkbox is checked either on a single user or multiple users that all of their data is processed and the action is actually taken e.g. the user is activated or deleted.

我想知道的是,使用表格上的复选框,我如何允许管理员选中复选框以选择多个用户,然后接受或删除它们?我知道我需要使用的SQL命令以及其他所有内容,但我只是不知道如何设置表,以便在单个用户或多个用户上检查复选框时是否处理了所有数据并执行了操作实际上是采取例如用户被激活或删除。

P.S. Sorry, I realised it is supposed to be a form. My bad!

附:对不起,我意识到这应该是一个表格。我的错!

1 个解决方案

#1


1  

In your form you should use [] (array of checkbox). ex.

在您的表单中,您应该使用[](复选框数组)。恩。

HTML :

while (iterate through registration requests) {
    echo "<input name='users[]' value='$user_id' type='checkbox'>"; 
}

While in backend you can get all checkbox's values as,

在后端,您可以获取所有复选框的值,

PHP :

$users = $_POST['users'];  // you have an array of all checked checkbox's values
$users_list = "'". implode("','", $users) ."'";

here, in $users_list, you'll have list of users. eg. 'user1','user2','user3','users4', .....

在这里,在$ users_list中,您将拥有用户列表。例如。 'user1','user2','user3','users4',.....

Then you can run query to mark all users as registered. ( pseudo query)

然后,您可以运行查询以将所有用户标记为已注册。 (伪查询)

UPDATE table_name SET approved = '1' WHERE user_id IN ($users_list);

you can also use above logic to delete requests also.

您也可以使用上面的逻辑来删除请求。

#1


1  

In your form you should use [] (array of checkbox). ex.

在您的表单中,您应该使用[](复选框数组)。恩。

HTML :

while (iterate through registration requests) {
    echo "<input name='users[]' value='$user_id' type='checkbox'>"; 
}

While in backend you can get all checkbox's values as,

在后端,您可以获取所有复选框的值,

PHP :

$users = $_POST['users'];  // you have an array of all checked checkbox's values
$users_list = "'". implode("','", $users) ."'";

here, in $users_list, you'll have list of users. eg. 'user1','user2','user3','users4', .....

在这里,在$ users_list中,您将拥有用户列表。例如。 'user1','user2','user3','users4',.....

Then you can run query to mark all users as registered. ( pseudo query)

然后,您可以运行查询以将所有用户标记为已注册。 (伪查询)

UPDATE table_name SET approved = '1' WHERE user_id IN ($users_list);

you can also use above logic to delete requests also.

您也可以使用上面的逻辑来删除请求。