title: check if email exists in MySQL database
body: <p>I am using the following PHP code to store data in my MySQL database, everything works perfect but I would like to build in a check; if the email already exists in the database then redirect to another page. (I'm a rookie when it comes to PHP)</p>
  
  <pre><code>&lt;?php
  
    if(empty($_POST['name']))
    {} else {
  
    define('DB_NAME', 'dbname');
    define('DB_USER', 'dbuser');
    define('DB_PASSWORD', 'dbpass');
    define('DB_HOST', 'host');
  
    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
  
    if (!$link) { die('could not connect: ' . mysql_error()); }
  
      $db_selected = mysql_select_db(DB_NAME, $link);
  
    if (!$db_selected) { die('can not use ' . DB_NAME . ': ' . mysql_error()); }
  
    $sql="INSERT INTO game (name, lastname, company, email, time) VALUES
  ('".$_POST['name']."','".$_POST['lastname']."','".$_POST['company']."','".$_POST['email']."','".$_POST['time']."')";
  
    if (!mysql_query($sql)) { die('Error: ' . mysql_error()); }
  
    mysql_close();
  
    }
  
  ?&gt;
  </code></pre>