Lani-Skyy Posted April 17, 2022 Share Posted April 17, 2022 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> Quote Link to comment https://forums.phpfreaks.com/topic/314707-trying-to-make-two-buttons-redirect-to-two-different-pages/ Share on other sites More sharing options...
Solution Lani-Skyy Posted April 17, 2022 Author Solution Share Posted April 17, 2022 There was a missing underscore in the third if statement, I'm literally so blind Quote Link to comment https://forums.phpfreaks.com/topic/314707-trying-to-make-two-buttons-redirect-to-two-different-pages/#findComment-1595425 Share on other sites More sharing options...
mac_gyver Posted April 17, 2022 Share Posted April 17, 2022 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. Quote Link to comment https://forums.phpfreaks.com/topic/314707-trying-to-make-two-buttons-redirect-to-two-different-pages/#findComment-1595427 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.