title: Prevent duplicate email address in PHP sign up form
body: <p>I've looked around the boards but there are no complete answers that I could find. I'm using PHP and MySQL to create and manage a volunteer sign up form. </p>
  
  <p>I need to make sure that there are no duplicate email addresses (email key is UNIQUE)</p>
  
  <p>Here is the code I'm working with, however I need help with understanding where to put the function as I'm also using check_input to strip slashes etc. </p>
  
  <p>The results are that the test entries using a duplicate email don't post to the database, however on the process page it still gives the user their confirmation instead of an error. </p>
  
  <p>The following code is on the process.php page, after the DB connection PHP and INSERT code: </p>
  
  <pre><code>      &lt;?php
  
    function createUser($email)
    {
         $sql = "SELECT * FROM vols2012 WHERE email='$email'" ;
  
         $result = mysql_query( $sql ) ;
  
         if( mysql_num_rows( $result ) &gt; 0 )
         {
     die( "There is already a user with that email!" ) ;
         }//end if
  
  
    function check_input($data, $problem='')
    {
        $data = trim($data);
        $data = stripslashes($data);
        $data = htmlspecialchars($data);
        if ($problem &amp;&amp; strlen($data) == 0)
        {
            show_error($problem);
        }
        return $data;
    }
  
    function show_error($myError)
    {
  
    }
  
    ?&gt;
  </code></pre>