title: php Real-Time form post submit
body: <p>Let me explain what I want to.</p>
  
  <p>I want to add a value in a list with db add without page change when I input in <code>form</code>, and click <code>submit</code>.</p>
  
  <p>but in this code, I must refresh one more time to add, and also added twice a time.</p>
  
  <p>How can I do that?</p>
  
  <pre><code>&lt;?php
      $conn = mysqli_connect('127.0.0.1','MYID','MYPASS','MYDB');
      $sql = "SELECT * FROM MYTABLE";
      $rs = mysqli_query($conn, $sql);
  
      $list = '';
      while($row = mysqli_fetch_array($rs)) {
              $list = $list."&lt;li&gt;&lt;a href=\"index.php?id={$row['id']}\"&gt;{$row['title']}&lt;/a&gt;&lt;/li&gt;";
      }
  
      $article = array(
          'title' =&gt; 'Welcome!',
          'description' =&gt; 'Hello, Web!'
      );
  
      if (isset($_GET['id'])){
          $filtered_id = mysqli_real_escape_string($conn, $_GET['id']);
  
          $sql = "SELECT * FROM topic WHERE id={$filtered_id}";
          $rs = mysqli_query($conn, $sql);
          $row = mysqli_fetch_array($rs);
          $article['title'] = $row['title'];
          $article['description'] = $row['description'];
      }
  
      if ($_POST['title'] != null){
          $sql_in = "INSERT INTO topic (title, description, created) VALUES ('{$_POST['title']}', '{$_POST['description']}', NOW())";
  
          $rs_in = mysqli_query($conn, $sql_in);
  
          if ($rs_in === false) {
                  $msg = mysqli_error($conn);
          } else {
                  $msg = 'Success.';
          }
      } else {
          $msg = 'Fill in';
      }
  ?&gt;
  
  &lt;!doctype html&gt;
  &lt;html&gt;
          &lt;head&gt;
                  &lt;meta charset="utf-8"&gt;
                  &lt;title&gt;WEB&lt;/title&gt;
          &lt;/head&gt;
  
          &lt;body&gt;
                  &lt;h1&gt;&lt;a href="index.php"&gt;WEB&lt;/a&gt;&lt;/h1&gt;
                  &lt;ol&gt;
                          &lt;?=$list?&gt;
                  &lt;/ol&gt;
                  &lt;details&gt;
                          &lt;summary&gt;Create&lt;/summary&gt;
                          &lt;form action="./index.php" method="POST"&gt;
                                  &lt;p&gt;&lt;input type="txt" name="title" placeholder="title"&gt;&lt;/p&gt;
                                  &lt;p&gt;&lt;textarea name="description" placeholder="description"&gt;&lt;/textarea&gt;&lt;/p&gt;
                                  &lt;p&gt;&lt;input type="submit"&gt;&lt;/p&gt;
                                  &lt;p&gt;&lt;?=$msg?&gt;&lt;/p&gt;
                          &lt;/form&gt;
                  &lt;/details&gt;
          &lt;/body&gt;
  &lt;/html&gt;
                  &lt;h2&gt;&lt;?=$article['title']?&gt;&lt;/h2&gt;
                  &lt;?=$article['description']?&gt;
          &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>