title: INSERT INTO statement not working
body: <p>I am fairly new to PHP/SQL coding and I am completely stumped as to why this coding isn't working. The database itself was made by my University, and so I am just trying to connect to it (I'm not sure if I'm able to give away the details so I took the connect coding out. I am at a basic level so heavy technical language will go over my head but any advice will be greatly appreciated!</p>
  
  <p>I am trying to insert the results from a form which is linked to the PHP file into the database table. I am unsure if I need to put anything in the PHP file to state this? But this is my code: </p>
  
  <pre><code>&lt;?php
  $conn = new mysqli($servername, $username, $password, $dbname);
  if ($conn-&gt;connect_error) {
     die("Connection failed: " . $conn-&gt;connect_error);
  } 
  echo "Connected successfully";
  // Connect to database
  $sql = "SELECT runnerid, position, eventid, date, finishtime, categoryid,  agegrade, pb FROM Results";
  $result = $conn-&gt;query($sql);
  
  if ($result-&gt;num_rows &gt; 0) {
      // output data of each row
      while($row = $result-&gt;fetch_assoc()) {
      { 
          echo "&lt;table&gt;";
          echo '&lt;table border=1&gt;&lt;tr&gt;&lt;th&gt;Runner ID&lt;/th&gt;&lt;th&gt;Position&lt;/th&gt;&lt;th&gt;Event ID&lt;/th&gt;&lt;th&gt;Date&lt;/th&gt;&lt;th&gt;Finish Time&lt;/th&gt;&lt;th&gt;Category ID&lt;/th&gt;&lt;th&gt;Age Grade&lt;/th&gt;&lt;th&gt;Personal Best&lt;/th&gt;&lt;/tr&gt;';
          echo "&lt;tr&gt;&lt;td&gt;";
          echo $row['runnerid'];
          echo "&lt;/td&gt;&lt;td&gt;";
          echo $row['position'];
          echo "&lt;/td&gt;&lt;td&gt;";
          echo $row['eventid'];
          echo "&lt;/td&gt;&lt;td&gt;";
          echo $row['date'];
          echo "&lt;/td&gt;&lt;td&gt;";
          echo $row['finishtime'];
          echo "&lt;/td&gt;&lt;td&gt;";
          echo $row['categoryid'];
          echo "&lt;/td&gt;&lt;td&gt;";
          echo $row['agegrade'];
          echo "&lt;/td&gt;&lt;td&gt;";
          echo $row['pb'];
          echo "&lt;/td&gt;
          &lt;/tr&gt;";
  
      }
      echo "&lt;/table&gt;";
  }
  } else {
   echo "0 results";
  }
  
  $sql = "INSERT INTO Results VALUES ('$_POST[runnerid]', '$_POST[position]' '$_POST[eventid]' '$_POST[date]' '$_POST[finishtime]' '$_POST[categoryid]' '$_POST[agegrade]' '$_POST[pb]')";
  
  $result = $conn-&gt;query($sql);
  if (!$result) {
      die('Could not insert data' . mysql_error()); 
  }
  $conn-&gt;close();
  ?&gt;
  </code></pre>
  
  <p>I have even tried the code without the <code>$_POST</code> coding in to just add new data but that's not working either.</p>