How to redirect to homepage when the submit button is clicked?

LPB

On my website i have a submit form:

this is the picture of the form

When i press this submit button the name is being saved on to my database, which is fine but i also want that button to take me to the homepage. Right now it take me to a page saying Fatal error like this

the error page

But when i press on the URL link and press enter it take me to the homepage. How can i redirect the page to homepage without selecting/pressing on the URL link and hitting enter? This is my code:

IMG: code

CODE:

<?php
  require_once "library/connection.php";
  $stmt = $conn->prepare("SELECT * FROM usernames ORDER BY scores DESC LIMIT 10");
  function createLeaderBoard($stmt)
  {
    $stmt->execute();
    $stmt->rowCount();
    $data = $stmt->fetchAll();
    foreach ($data as $row) 
    {
?>
       <tr>
          <td><?php echo $row['users']; ?></td>
          <td><?php echo $row['Scores']; ?></td>
       </tr>
<?php
    }
  }
  if (isset($_POST["firstname"])) 
  {
     $firstname = $_POST["firstname"];
     $score     = $_POST["score"];
     $stmt      = $conn->prepare("INSERT INTO `usernames` (`users`, `Scores`)     VALUES ('" . $firstname . "','" . $score . "');");
     $stmt->execute();
     $result = $stmt->fetch(PDO::FETCH_ASSOC);
  }
?>

Hope my English is good and i also hope you can understand me. All the help will be appreciated :)

Parth Chavda

chnage this

if (isset($_POST["firstname"])) {
     $firstname = $_POST["firstname"];
     $score     = $_POST["score"];
     $stmt      = $conn->prepare("INSERT INTO `usernames` (`users`, `Scores`)     VALUES ('" . $firstname . "','" . $score . "');");
   $stmt->execute();
   $result = $stmt->fetch(PDO::FETCH_ASSOC);
}

to

     if (isset($_POST["firstname"])) {
             $firstname = $_POST["firstname"];
             $score     = $_POST["score"];
 $stmt      = $conn->prepare("INSERT INTO `usernames` (`users`, `Scores`)     VALUES ('" . $firstname . "','" . $score . "')");
    if($stmt->execute()){
            // redirect the user to homepage.php
            header("Location: homepage.php");
            exit();
        }

    }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to redirect to homepage when the submit button is clicked?

From Dev

How to prevent form submit when a button clicked?

From Dev

How to prevent form submit when a button clicked?

From Dev

Javascript redirect user when submit button is clicked based on radio button value

From Dev

How can i put a progress cursor when Submit button clicked

From Dev

how to set semi-transparent jframe when "submit" button is clicked?

From Dev

How to check if any of the Radio buttons are checked or not when clicked on submit button

From Dev

How to submit textbox value when clicked some button to angularjs function?

From Dev

What happens when submit button is clicked

From Dev

Display another DIV when submit button is clicked

From Dev

error blinks when submit button is clicked

From Dev

Display another DIV when submit button is clicked

From Dev

Display an image when submit button is clicked

From Dev

How to replace button with loading gif image when the submit button is clicked then on success remove form and replace with a success message

From Dev

How to replace button with loading gif image when the submit button is clicked then on success remove form and replace with a success message

From Dev

HTML/CSS Button when clicked changes into input field and submit button

From Dev

How to trigger a modal on submit button & redirect Rails

From Dev

How to open a Bootstrap modal when a Submit button redirecting to a different page is clicked?

From Dev

How to scroll to a particular div after reloading the page when the submit button is clicked?

From Dev

how to insert the textbox values to the database mysql using php oops concept when clicked on the Submit button

From Dev

How to get value of generated row value for another action when generated submit button is clicked

From Dev

How to write a function in jsp which can be called when the submit button is clicked

From Dev

which submit button was clicked

From Dev

which submit button was clicked

From Dev

How to disable a button when clicked?

From Dev

How to remove a button when it is clicked?

From Dev

how to disable a html button after it has been clicked not a submit button

From Dev

How can I redirect to another template when the submit button is pressed in Alert Ionic Framework?

From Dev

Calling Classic ASP Function when Form Submit Button is clicked

Related Related

  1. 1

    How to redirect to homepage when the submit button is clicked?

  2. 2

    How to prevent form submit when a button clicked?

  3. 3

    How to prevent form submit when a button clicked?

  4. 4

    Javascript redirect user when submit button is clicked based on radio button value

  5. 5

    How can i put a progress cursor when Submit button clicked

  6. 6

    how to set semi-transparent jframe when "submit" button is clicked?

  7. 7

    How to check if any of the Radio buttons are checked or not when clicked on submit button

  8. 8

    How to submit textbox value when clicked some button to angularjs function?

  9. 9

    What happens when submit button is clicked

  10. 10

    Display another DIV when submit button is clicked

  11. 11

    error blinks when submit button is clicked

  12. 12

    Display another DIV when submit button is clicked

  13. 13

    Display an image when submit button is clicked

  14. 14

    How to replace button with loading gif image when the submit button is clicked then on success remove form and replace with a success message

  15. 15

    How to replace button with loading gif image when the submit button is clicked then on success remove form and replace with a success message

  16. 16

    HTML/CSS Button when clicked changes into input field and submit button

  17. 17

    How to trigger a modal on submit button & redirect Rails

  18. 18

    How to open a Bootstrap modal when a Submit button redirecting to a different page is clicked?

  19. 19

    How to scroll to a particular div after reloading the page when the submit button is clicked?

  20. 20

    how to insert the textbox values to the database mysql using php oops concept when clicked on the Submit button

  21. 21

    How to get value of generated row value for another action when generated submit button is clicked

  22. 22

    How to write a function in jsp which can be called when the submit button is clicked

  23. 23

    which submit button was clicked

  24. 24

    which submit button was clicked

  25. 25

    How to disable a button when clicked?

  26. 26

    How to remove a button when it is clicked?

  27. 27

    how to disable a html button after it has been clicked not a submit button

  28. 28

    How can I redirect to another template when the submit button is pressed in Alert Ionic Framework?

  29. 29

    Calling Classic ASP Function when Form Submit Button is clicked

HotTag

Archive