title: Undefined Variable PHP + MySQL
body: <p>I know stackoverflow disapproves of repeat questions, but bear with me as I have scanned many similar questions without finding specific resolutions that will help me. (Mostly they mention things about avoiding database insertions)</p>
  
  <p>I encounter these error messages:</p>
  
  <pre><code>here db connection success
  Notice: Undefined variable: firstname in  C:\xampp\htdocs\practice_connection_app\submit.php on line 10
  
  Notice: Undefined variable: lastname in  C:\xampp\htdocs\practice_connection_app\submit.php on line 10
  
  Notice: Undefined variable: conn in   C:\xampp\htdocs\practice_connection_app\submit.php on line 11
  
  Fatal error: Call to a member function exec() on null in C:\xampp\htdocs\practice_connection_app\submit.php on line 11
  </code></pre>
  
  <p>The first result simply shows that I have connected to my database which I made using phpMyadmin. </p>
  
  <p>Here is my relevant code (my html submission page which calls on a php action):</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta charset="UTF-8"&gt;
          &lt;title&gt;student info&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;br&gt;
          Enter your first name and last name in the corresponding boxes.
          &lt;br&gt;
          &lt;form  action="submit.php" method="POST"&gt;
              First: &lt;input type="text" name="firstname"/&gt;
          &lt;br&gt;
              Last: &lt;input type="text" name="lastname"/&gt;
          &lt;br&gt;
          &lt;input type="submit"&gt;
          &lt;/form&gt;
  
  
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>the database connection (I think)</p>
  
  <pre><code>&lt;?php
  echo 'here';
      $dsn = 'mysql:host=localhost;dbname=practice_students';
      $username = 'test_usr';
      $password = 'pa55word';
  
      try {
          $db = new PDO($dsn, $username, $password);
          echo 'db connection success';
      } catch (PDOException $e) {
          $error_message = $e-&gt;getMessage();
          include('database_error.php');
          exit();
      }
  
  ?&gt;
  </code></pre>
  
  <p>AND my php submit page</p>
  
  <pre><code>&lt;?php
  echo 'here ';
      $dsn = 'mysql:host=localhost;dbname=practice_students';
  
  
      try {
          $db = new PDO($dsn);
          echo 'db connection success';
          $sql = "INSERT INTO people (firstname, lastname)
                 VALUES ('$firstname', '$lastname')";
          $conn-&gt;exec($sql);
          echo "Now we know your name! Hi," . " " . $firstname . " " . $lastname;
      } catch (PDOException $e) {
          $error_message = $e-&gt;getMessage();
          include('database_error.php');
          exit();
      }
  ?&gt;
  </code></pre>
  
  <p>I understand that I may need to do some 'cleaning up' to avoid database insertions, but for now I would just like to know how I can ensure my submissions are going to the database and can be returned. </p>
  
  <p>Thanks in advance!</p>