I have a little problem here.
The data inserts into the database, but it do insert when I open the page.
I want to insert the data when I push the submit button, not when the page is loaded/refreshed. Hope someone can help me!
Here is the code:
<html>
  <head>
  </head>
  <body>
    <h2>Arbeidsliste</h2>
    <div id ="insert">
      <form action="index.php" method="post">
        <p>
          <label for="dato">Dato: </label>
          <input type="date" name="dato" class="field">
        </p>
        <p>
          <label for="start">Start: </label>
          <input type="time" name="start" class="field">
        </p>
        <p>
          <label for="slutt">Slutt: </label>
          <input type="time" name="slutt" class="field">
        </p>
        <p>
          <label for="pause">Pause: </label>
          <input type="number" name="pause" class="field">
        </p>
        <p>
          <input type="submit">
        </p>
      </form>
    </div>
    <?php
        $servername = "localhost";
        $username = "root";
        $password = "";
        $dbname = "timer";
        // Create connection
        $conn = new mysqli($servername, $username, $password, $dbname);
        // Check connection
        if ($conn->connect_error) {
            die("Connection failed: " . $conn->connect_error);
        } 
        $sql = "INSERT INTO meny (dato, start, slutt, pause)
                VALUES ('2016-04-01', '12:00', '20:00', '30')";
        if ($conn->query($sql) === TRUE) {
            echo "New record created successfully";
        } else {
            echo "Error: " . $sql . "<br>" . $conn->error;
        }
        $conn->close();
    ?>
  </body>
</html>
 
     
     
     
    