title: How do I submit form data to a database and redirect someone to URL?
body: <p>PHP Newbie here: Quick question on forms and php, </p>
  
  <p>Form in Html page</p>
  
  <pre><code> &lt;form class="form" id="form" onsubmit="return validateForm()" method="post"           action="submitdatabase.php"&gt;
  </code></pre>
  
  <p>I can insert data into my database successfully but how do I direct them to a certain URL as well?</p>
  
  <p>If it helps, below is my PHP, needless to say it doesn't work: </p>
  
  <pre><code>&lt;?php
      $con = mysql_connect("localhost","root","");
      if (!$con) {
          die('Could not connect: ' . mysql_error());
      }
  
      mysql_select_db("database", $con);
      $sql="INSERT INTO leads (fname, lname, address, phone, email)
            VALUES ('$_POST[fname]','$_POST[lname]','$_POST[address]','$_POST[phone]','$_POST[email]')";
      if (!mysql_query($sql,$con)) {
          die('Error: ' . mysql_error());
      }
  
      mysql_close($con)
      header("Location: URLREDIRECTION.com")
  ?&gt;
  </code></pre>