Jump to content

Trying to make two buttons redirect to two different pages


Lani-Skyy
Go to solution Solved by Lani-Skyy,

Recommended Posts

When I click the button "baru", it sends me to the page create_pertandingan.php, however, when I click the button "lama", nothing happens. I'm clearing the post array so the user can give another input after reloading.

<?php
    session_start();
    include("sambungan.php");

    if ($_POST) {
        if (isset($_POST["baru"])) {
            $_POST = array();
            header("Location:./create_pertandingan.php");
        }

        if (isset($POST["lama"])) {
            $_POST = array();
            header("Location:./main.php");
        }
    }
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    <link href="styles.css" rel="stylesheet">
    <title>SPPC</title>
</head>
<body>
    <div>
    <form action="load_pertandingan.php" method="post">
        <p>Load Pertandingan:</p>
        <input type="submit" name="baru" value="Baru">
        <input type="submit" name="lama" value="Lama">
    </form>
    </div>
</body>
</html>

 

Link to comment
Share on other sites

there's not really any point in using a post method form to pick which page to go to using a header() redirect (which causes a get request for those pages, the post data won't exist after the redirect anyway.)

if you are doing this so that you can have 'buttons' to click on, just use a link that is a button.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.