PHP: Check if email already exists when running this code
<p>I have built a very simple PHP form that allows a user to send an application using the following PHP code:</p>

<pre><code>if($_SERVER['REQUEST_METHOD'] == 'POST')
    {
        $host = '###';
        $username = '###';
        $pass = '###';

        mysql_connect($host,$username,$pass);
        mysql_select_db("###");

        $status    = mysql_real_escape_string($_POST['status']);
        $firstname = mysql_real_escape_string($_POST['firstname']);
        $lastname  = mysql_real_escape_string($_POST['lastname']);
        $email     = mysql_real_escape_string($_POST['email']);
        $url       = mysql_real_escape_string($_POST['url']);

        $query = "INSERT INTO creathive_applications 
                  VALUES (NULL,'$status','$firstname','$lastname','$email','$url')";

        $result = mysql_query($query) or trigger_error(mysql_error().". Query: ".$query);
    }
</code></pre>

<p>What I want to do is make sure that the same person doesn't apply TWICE so if the email address already exists in the database then it will show a message on the form saying "sorry looks like you've already applied".</p>

<p>Here is the HTML form, and I have added the message inside the fieldset, so need to do a) show this message if the email exits or show success message and then b) add #membership form to the url to make the view jump to form on the page so that the user will see the messages. Can any help with this? THANKS</p>

<pre><code>    &lt;form action="" method="post"&gt;
                            &lt;fieldset id="membershipform"&gt;
                    &lt;div id="error"&gt;&lt;p&gt;sorry email in use&lt;/p&gt;&lt;/div&gt;
&lt;div id="success"&gt;&lt;p&gt;Thanks your application has been sent&lt;/p&gt;&lt;/div&gt;
                                &lt;ul class="clearfix"&gt;
                                    &lt;li id="li-status"&gt;
                                        &lt;span&gt;I am a:&lt;/span&gt;
                                        &lt;menu&gt;
                                            &lt;li&gt;&lt;label for="student"&gt;&lt;input type="radio" name="status" id="student" checked="checked" value="Graduate" /&gt; Graduate&lt;/label&gt;&lt;/li&gt;
                                            &lt;li&gt;&lt;label for="student2"&gt;&lt;input type="radio" name="status" id="student2" value="Undergraduate" /&gt; Undergraduate&lt;/label&gt;&lt;/li&gt;
                                        &lt;/menu&gt;
                                    &lt;/li&gt;
                                    &lt;li id="li-firstname"&gt;
                                        &lt;label for="firstname"&gt;First Name&lt;/label&gt; &lt;input name="firstname" type="text" placeholder="First Name" id="firstname" title="First Name" /&gt;
                                    &lt;/li&gt;
                                    &lt;li id="li-lastname"&gt;
                                        &lt;label for="lastname"&gt;Last Name&lt;/label&gt; &lt;input name="lastname" type="text" placeholder="Last Name" id="lastname" title="Last Name" /&gt;
                                    &lt;/li&gt;
                                    &lt;li id="li-email"&gt;
                                        &lt;label for="email"&gt;Email address&lt;/label&gt; &lt;input name="email" type="text" placeholder="Email address" id="email" title="Email address" /&gt;
                                    &lt;/li&gt;
                                    &lt;li id="li-url"&gt;
                                        &lt;label for="url"&gt;URL&lt;/label&gt; &lt;input name="url" type="text" placeholder="URL of something you've made" id="url" title="URL of something you've made" /&gt;
                                    &lt;/li&gt;
                                    &lt;li id="li-buttons"&gt;
                                        &lt;input name="submit" type="submit" value="Send Application &amp;#9658;" title="Send Application" /&gt;
                                    &lt;/li&gt;
                                &lt;/ui&gt;
                            &lt;/fieldset&gt;
                        &lt;/form&gt;
</code></pre>
