Basic PHP: Multiple submit buttons in a single form

11
3



By using this method, we can save a lot of time by not having to code extra forms. Also learn how to disable reporting of notices.

To view the example.php file click on the following link:

To view the temp.php file click on the following link:

Nguồn:https://wijstaanvooronzegrondrechten.org/

Xem Thêm Bài Viết Khác:https://wijstaanvooronzegrondrechten.org/cong-nghe

11 COMMENTS

  1. using this code
    <?php
    session_start();
    $_SESSION['message'] = $_GET['id'];
    header('location: index.php');
    ?>

    the file is named features.php
    being call from a shopping cart.

    <span class="pull-left"><a href="features.php?id=<?php echo $row['id']; ?>" class="btn btn-primary btn-sm">
    View</a></span>

    the button is added to each box as it loops through this section. what I need is to be able to launch a page from within features.php i think. where id = 1 then show 1.html or 1.php where id = 3 then show 3.html or 3.php

    any help would be appreciated. Thanks

  2. SOLUTION OF THE ERROR:-
    ======================
    <?php
    if(!(empty($_POST["TEAM"])))
    {
    echo "TEAM";
    }
    if(!(empty($_POST["MATCH"])))
    {
    echo "MATCH";
    }
    if(!(empty($_POST["REFEREE"])))
    {
    echo "REFEREE";
    }
    if(!(empty($_POST["PLAYER"])))
    {
    echo "PLAYER";
    }
    ?>

  3. The error is actually something you should pay attention to, rather than ignore.
    When you click the button2, what happens is this:
    Temp.php is going to the first line of code and checking for $_POST['1'] which is undefined at this point, because your form only sent $_POST['2'].

    In order to take care of this problem the right way(Rather than making sure php doesn't show you errors…), on your IF statement, you should first check to see if $_POST['1'] is defined.
    To do this, use the method isset in the following matter:

    if(isset($_POST['1']) { echo "You have pressed 1";} else …

    Notice that on your else statement, for the sake of completeness, you must check whether or not $_POST['2'] is defined aswell, before you take actions on the object attribute.

LEAVE A REPLY

Please enter your comment!
Please enter your name here