title: Storing emails in a MySQL database using an HTML Form and PHP
body: <p>I am working to make a form where I can collect names and email addresses and send them to a MySQL database for storage. I wrote the HTML and PHP file and it seems to be working. It echoes "Thank you for entering an email!". When I look at the database it creates a line for the data but all the fields are blank. I am not sure what's going on, and this is the first time I have worked with a database. Thanks for all your help!</p>
  
  <p>HTML</p>
  
  <pre><code>&lt;form action='/submitEmail.php' action='POST'&gt;
    &lt;p&gt;First name: &lt;input type='text' id="firstname" name='firstname' /&gt;&lt;/p&gt;
    &lt;p&gt;Last name: &lt;input type='text' id="lastname" name='lastname' /&gt;&lt;/p&gt;
    &lt;p&gt;Email: &lt;input type='text' name='email' /&gt;&lt;/p&gt;
    &lt;input type='submit' value='Submit Email' /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>PHP</p>
  
  <pre><code>&lt;?php
    // Connecting to the MySQL server
    $host="myHost";
    $user_name="myUsername";
    $pwd="myPassword";
    $database_name="myDatabase"; //assuming you created this
    $db=mysql_connect($host, $user_name, $pwd);
    if (mysql_error() &gt; "") print mysql_error() . "&lt;br&gt;";
    mysql_select_db($database_name, $db);
    if (mysql_error() &gt; "") print mysql_error() . "&lt;br&gt;";
    // Storing form values into PHP variables
    $firstname = $_POST["firstname"]; // Since method="post" in the form
    $lastname = $_POST["lastname"];
    $email = $_POST["email"];
    // Inserting these values into the MySQL table
    // we created above
    $query = "insert into email_list (firstname, lastname, email) values ('" . $firstname . "', '" . $lastname . "', '" . $email . "')";
    $result = mysql_query($query);
    // mysql_query() is a PHP function for executing
    // MySQL queries
    echo "&lt;p&gt;Thank you for entering an email!&lt;/p&gt;";
  ?&gt;
  </code></pre>