PHP在一页中生成的多种形式

发布于 2025-02-11 18:51:58 字数 1327 浏览 0 评论 0原文

我有一段时间的循环,生成了许多表格,其中包含以后要提交的信息。

我正在考虑将所有“名称”变量重命名为从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.

Here a picture to explain:
enter image description here

<?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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文