title: Inserting input field value to database and displaying result on same page
body: <p>I am starting to learn the basics of SQL and PHP codes.</p>
  
  <p>I am trying to create a simple newsletter subscription page. this would require the user to enter their email and submit. That will then get added to my database.</p>
  
  <p>Now, this works well when the HTML and PHP code are separate and the submission occurs but redirects to the PHP page with the echo.</p>
  
  <p>I want to get the message on the same page and I tried merging the PHP code in the page as below</p>
  
  <pre><code>&lt;?php 
  if($_SERVER['REQUEST_METHOD'] === 'POST'){
  mysql_connect("hostname", "username", "password"); 
  mysql_select_db("db name"); 
  $user = $_POST['email']; 
  $query = "INSERT INTO tablename(columname)VALUES('$email')"; 
  echo "inserted";
  } 
  ?&gt;
  
  &lt;html&gt; 
  &lt;form method="POST" action="" &gt; 
  &lt;label&gt;Email:&lt;/label&gt; &lt;input name="email" type="text"/&gt;
  &lt;input type="submit" name="submit" value="Insert" /&gt; &lt;br&gt;
  &lt;/form&gt;   
  &lt;/html&gt;
  </code></pre>
  
  <p>Hoever with this code it just doesnt do anything.</p>
  
  <p>What have am I doing wrong here? Appreciate your expert advice.</p>