PHP在一页中生成的多种形式
我有一段时间的循环,生成了许多表格,其中包含以后要提交的信息。
我正在考虑将所有“名称”变量重命名为从while循环中的用户ID重命名,但是如何在邮政检查中称其为呢?
这是我的代码(以简化版本)的示例,我可以拥有多种形式。 3个重要变量是: 按钮中的名称|选项中的名称|提交的名称
提前感谢您的帮助!
edit :
简单地说明,我有一个列表,其中所有现有角色下拉列表和一个“添加角色”按钮。
通过单击“添加角色”按钮,我希望它可以检索昵称和按钮行的角色将它们发送到我的数据库。
<?php while($user = $getUser -> fetch()){
<form method="post" action="">
<p>Pseudo:</p>
<button name="pseudo" value="<?php echo $user["id_user"]; ?>">
<?php echo $user["pseudo"]; ?>
</button>
<select class="form-select" aria-label="Default">
<option selected>Choose</option>
<?php
$getListRole = $bdd -> prepare('SELECT * FROM role');
$getListRole->execute(array());
while($role = $getListRole -> fetch()){
?>
<option name="roleAdd" value="<?php echo $role["id_role"]; ?>">
<?php echo $role["nom"]; ?>
</option>
<?php } ?>
</select>
<button type="submit" name="addRole">Add role</button>
</form>
<?php } ?>
I have a while loop that generates a number of forms containing information that I want to submit later.
I was thinking of renaming all my "name" variables with the ID of the user from the while loop, but how do I call it in the post check?
Here is an example of my code (in reduced version), I can have a multitude of forms.
The 3 important variables are:
the name in button | the name in option | the name of the submit
thank you in advance for your help !
EDIT :
To explain simply, I have a list of players with a dropdown of all existing roles and an "add role" button.
By clicking on the "add role" button, I would like it to retrieve the nickname and the role of the button line to send them to my database.
<?php while($user = $getUser -> fetch()){
<form method="post" action="">
<p>Pseudo:</p>
<button name="pseudo" value="<?php echo $user["id_user"]; ?>">
<?php echo $user["pseudo"]; ?>
</button>
<select class="form-select" aria-label="Default">
<option selected>Choose</option>
<?php
$getListRole = $bdd -> prepare('SELECT * FROM role');
$getListRole->execute(array());
while($role = $getListRole -> fetch()){
?>
<option name="roleAdd" value="<?php echo $role["id_role"]; ?>">
<?php echo $role["nom"]; ?>
</option>
<?php } ?>
</select>
<button type="submit" name="addRole">Add role</button>
</form>
<?php } ?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论