title: How to insert form data into PDO using prepared statements?
body: <p>SO I learned this from w3schools. . .however the example used data directly injected into the code. I was wondering how can I use the same code block but receive data from a form instead</p>
  
  <pre><code>&lt;?php
  $servername = "localhost";
  $username = "username";
  $password = "password";
  $dbname = "myDBPDO";
  
  try {
  $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username,      
  $password);
  // set the PDO error mode to exception
  $conn-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  
  // prepare sql and bind parameters
  $stmt = $conn-&gt;prepare("INSERT INTO MyGuests (firstname, lastname, 
  email) 
  VALUES (:firstname, :lastname, :email)");
  $stmt-&gt;bindParam(':firstname', $firstname);
  $stmt-&gt;bindParam(':lastname', $lastname);
  $stmt-&gt;bindParam(':email', $email);
  
  // insert a row
  $firstname = "John";
  $lastname = "Doe";
  $email = "john@example.com";
  $stmt-&gt;execute();
  
  // insert another row
  $firstname = "Mary";
  $lastname = "Moe";
  $email = "mary@example.com";
  $stmt-&gt;execute();
  
  // insert another row
  $firstname = "Julie";
  $lastname = "Dooley";
  $email = "julie@example.com";
  $stmt-&gt;execute();
  
  echo "New records created successfully";
  }
  catch(PDOException $e)
  {
  echo "Error: " . $e-&gt;getMessage();
  }
  $conn = null;
  ?&gt;
  </code></pre>