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

What happens when submit button is clicked

From Dev

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

From Dev

Calling Classic ASP Function when Form Submit Button is clicked

From Dev

Display another DIV when submit button is clicked

From Dev

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

From Dev

How to prevent form submit when a button clicked?

From Dev

How to disable a button when clicked?

From Dev

which submit button was clicked

From Dev

How can i put a progress cursor when Submit button clicked

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 set semi-transparent jframe 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

error blinks when 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

Display another DIV when submit button is clicked

From Dev

How to prevent form submit when a button clicked?

From Dev

which submit button was 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 get value of generated row value for another action when generated submit button is clicked

From Dev

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

From Dev

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

From Dev

Display an image when submit button is clicked

From Dev

How to trigger a modal on submit button & redirect Rails

From Dev

How to write a function in jsp which can be called when the 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 can I redirect to another template when the submit button is pressed in Alert Ionic Framework?

From Dev

How to remove a button when it is clicked?

From Dev

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

Related Related

  1. 1

    What happens when submit button is clicked

  2. 2

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

  3. 3

    Calling Classic ASP Function when Form Submit Button is clicked

  4. 4

    Display another DIV when submit button is clicked

  5. 5

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

  6. 6

    How to prevent form submit when a button clicked?

  7. 7

    How to disable a button when clicked?

  8. 8

    which submit button was clicked

  9. 9

    How can i put a progress cursor when Submit button clicked

  10. 10

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

  11. 11

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

  12. 12

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

  13. 13

    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

  14. 14

    error blinks when submit button is clicked

  15. 15

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

  16. 16

    Display another DIV when submit button is clicked

  17. 17

    How to prevent form submit when a button clicked?

  18. 18

    which submit button was clicked

  19. 19

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

  20. 20

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

  21. 21

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

  22. 22

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

  23. 23

    Display an image when submit button is clicked

  24. 24

    How to trigger a modal on submit button & redirect Rails

  25. 25

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

  26. 26

    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

  27. 27

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

  28. 28

    How to remove a button when it is clicked?

  29. 29

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

HotTag

Archive