简体   繁体   中英

PHP, html: How to pass the button value to post

I'm trying to pass in the value of the button to $_POST["class_name"] so I can use it in selectclass.php . I want to be able to click on the button in the table and have $_POST = the value of the button, or even better, if possible, the class_id next to the button. Any help would be really appreciated.

 <tbody>
            <form action="selectclass.php" method="post">
            <?php foreach ($classes as $class): ?>

                <tr>

                  <th><button type="text" name = "class_id"><?=$class["class_name"]?></button></th>
                  <th><?=$class["class_id"] ?></th>

                </tr>

         <?php endforeach ?>
         </form>
        </tbody>

If you want it to have a value, give it one using the value attribute:

<button type="text" name="class_id" value="some_value">

See <button> on MDN

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM