Nathaniel
Nathaniel

Reputation: 89

button as submit form

im trying to make something, and now i came to the part where i created a button that should lock the topic, but i don't know how to make it work like submit form, when i press it it should lock the topic, but nothing happens:

    echo '<br><div class="ticket_info">';
    if($stanje == 0 ) {  
       echo ' <button class="lockticket" name="lockticketbutton">Zatvori</button></a> ';
    }
    else if($stanje != 0 ) {
         echo ' <button class="lockticket" name="unlockticketbutton">Otvori</button></a>';  
    }

    echo '
       Postavio: '.$output['Postavio'].' --- ['.$output['Naslov'].']

    </div>

    </br><div class="ticket_info2">

    '.$output['Text'].'

    </div>

    ';

And this is what it should output:

if(isset($_POST['lockticketbutton']))
{
    $id = $_GET['id'];

    $query = mysqli_query($con, "UPDATE `Dashboard` SET `Status` = '1' WHERE `ID` = '$id'");

    if($query)
    {
      header('Location: ' . $_SERVER['HTTP_REFERER']);
    }
    else
    {
        header('location: dashboard.php');
    }
}

Upvotes: 0

Views: 89

Answers (2)

Mosh Feu
Mosh Feu

Reputation: 29239

To use a button as Submit you need to put it into form.

Note: according to w3schools:

If you use the <button> element in an HTML form, different browsers may submit different values. Use <input> to create buttons in an HTML form.

Upvotes: 1

Abdul Razak
Abdul Razak

Reputation: 2794

you can submit the button by using following code

<form action ="your php file name" method ="post">
    <button type= "submit" class="lockticket" name="odgovoritiket" >Otvori</button>
</form>

Upvotes: 1

Related Questions