title: How to insert multiple values into a table in php
body: <p>I have learnt and been taught how to insert a single value into a column in a table but i cant get my head around inserting multiple values into multiple columns in the same table</p>
  
  <p>I want to be able to add an id, first name, second name and email, can anyone help? please.</p>
  
  <p>I have a php file to connect to the database along with the function to insert into the database.</p>
  
  <p><strong>db.php</strong></p>
  
  <pre><code>&lt;?php
  
  function getSQLConnection() {
  $mysqlConnection = new PDO('mysql:host=localhost;dbname=isad235_100000', "root", "");
  
  
  return $mysqlConnection;
  }
  
  function insertSingleValue($tableName, $columnName, $value) {
  $sql = 'INSERT into ' . $tableName . '(' . $columnName . ') VALUES(:Value)';
  
  $mySqlConnection = getSQLConnection();
  $sqlStatement = $mySqlConnection-&gt;prepare($sql);
  $sqlStatement-&gt;bindValue(":Value", $value, PDO::PARAM_STR);
  
  $bReturn = false;
  try {
      $sqlStatement-&gt;execute();
      //if we get to here it's all worked.
      $bReturn = true;
  } catch (PDOException $e) {
      echo $e-&gt;getMessage();
  }
  return $bReturn;
  }
  
  function getResults($tablename) {
  $sql = "SELECT * FROM " . $tablename;
  
  $mysqlConnection = getSQLConnection();
  
  $ResultSet = $mysqlConnection-&gt;query($sql);
  return $ResultSet;
  }
  
    ?&gt;
  </code></pre>
  
  <p>and a webpage file which gets the data and calls the function to insert.</p>
  
  <p><strong>index.php</strong></p>
  
  <pre><code>&lt;?php
  include_once 'db.php';
  
  if (isset($_POST['first_name'])) {
  $success = insertSingleValue("members", "first_name", $_POST['first_name']);
  if (!$success)
      echo 'Sorry, the insert failed';
  }
  $Results = getResults("members");
  ?&gt;
  
   &lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
      &lt;title&gt;&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
      &lt;form action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" method="post"&gt;
  
          &lt;label id="lblName" for="first_name"&gt;First Name&lt;/label&gt;
  
          &lt;input type="text" name="first_name" /&gt;
  
          &lt;input type="submit" name="submit" value="Submit" /&gt;
      &lt;/form&gt;
      &lt;table border="1"&gt;
          &lt;tr&gt;&lt;th&gt;Name&lt;/th&gt;
          &lt;/tr&gt;
  
  &lt;?php
  if (isset($Results)) {
  foreach ($Results as $row) {
      echo '&lt;tr&gt;&lt;td&gt;';
      echo $row['first_name'];
      echo '&lt;/td&gt;&lt;/tr&gt;';
      }
  }
  ?&gt;
  
      &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>