title: PHP chat submit refresh button
body: <p>I just started working with SQL and I am making a chat.</p>
  
  <p>Few questions:-</p>
  
  <p>1) If you come from the index.php (the site where you can put in a username only)
  You will come to home.php. Than in the top it says: You didnt send a message yet. and everytime if i refresh it just uploads the last message. I know there is a fix i just couldnt find it.</p>
  
  <p>2) If i press on the submit button it refreshes the page and goes all the way up. So you have to scroll all the way down to enter and see your message. + i can fix this without refresching but than you dont see any messages beign send.</p>
  
  <pre><code>&lt;?php
  
  if (isset($_POST["afzender"])){
      $_SESSION['afzender'] = $_POST['afzender'];
  }
  
  $servername = "localhost";
  $username = "*******";
  $password = "******";
  $dbname = "*****";
  
  // Create connection
  $conn = new mysqli($servername, $username, $password, $dbname);
  // Check connection
  if ($conn-&gt;connect_error) {
      die("Connection failed: " . $conn-&gt;connect_error);
  } 
  
  $sql = "INSERT INTO 'chatbox_berichten'
  (''id', 'afzender', 'chatbox_id', 'bericht', 'tijd')
  VALUES (NULL, '".$_SESSION['afzender']."', '', '".$_POST['bericht']."', CURRENT_TIMESTAMP);";
  echo $sql;
  if ($conn-&gt;query($sql) === TRUE) {
      echo "Succesvol Toegevoegd.";
  } else {
      echo $conn-&gt;connect_error;
  }
  echo "&lt;hr/&gt;";
  
  $sql = "SELECT * FROM chatbox_berichten";
  $result = $conn-&gt;query($sql);
  
  if ($result-&gt;num_rows &gt; 0) {
      echo "&lt;table border='2'&gt;";
      // output data of each row
      while($row = $result-&gt;fetch_assoc()) {
          echo "&lt;tr&gt;&lt;td&gt;" . $row["id"]. "&lt;td&gt;" . $row["afzender"]. "&lt;td&gt;" . $row["bericht"]. "  &lt;td&gt;" . $row["tijd"]. "&lt;/td&gt;&lt;/tr&gt;";
      }
      echo "&lt;/table&gt;";
  } else {
      echo "0 results";
  }
  
  
  $conn-&gt;close();
  ?&gt;
  &lt;?php echo $_SESSION['afzender']; ?&gt;        
  &lt;form action="home.php" method="post"&gt;
  Bericht: &lt;input type="text" name="bericht"&gt;&lt;br&gt;
  &lt;input type="submit"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I know the code looks messy. I have no lessons whatsoever in making it looking better.</p>
  
  <p>So any help would be appreciated.</p>