Php duplicate email message and email notifications

I'm really a newbie in Php. I made a registration form where after registration it will be inserted into my database but after a few minutes i realized that after i sign up again using the same email address it enters again and that's a really big problem for me. Also i want to send an e-mail notification to the user after the registration but i don't have the knowledge to that and i already search many answer but nothings working for me. Can you help me with my problem:(

Here is my code for the registration form:

<?php
//Start session
session_start();

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <meta charset="utf-8">
    <title> Athan Motorcycle Spare Parts and Accesories</title>
    <link rel="stylesheet" href="css/bootstrap.css" type="text/css"/>

    <script type="text/javascript">
function validateForm()
{

var a=document.forms["abc"]["firstname"].value;
var b=document.forms["abc"]["lastname"].value;
var d=document.forms["abc"]["email"].value;
var e=document.forms["abc"]["pword"].value;
var f=document.forms["abc"]["ambot"].value;
var g=document.forms["abc"]["number"].value;
var h=document.forms["abc"]["house"].value;
var i=document.forms["abc"]["street"].value;
var j=document.forms["abc"]["city"].value;
if ((a==null || a==""))
 {
 alert("you must enter your username");
 return false;
 }
if ((b==null || b==""))
 {
 alert("you must enter your password");
 return false;
 }
if ((d==null || d==""))
 {
 alert("you must enter your email address");
  return false;
 }
if ((e==null || e==""))
 {
 alert("you must enter your password");
 return false;
 }
if ((f==null || f==""))
 {
 alert("Retype password");
 return false;
 }
if ((g==null || g==""))
 {
 alert("you must enter your contact number");
 return false;
}
if ((h==null || h==""))
{
alert("you must enter your house location");
 return false;
}
if ((i==null || i==""))
{
 alert("you must enter your Street");
 return false;
}
if ((j==0 || j==""))
{
 alert("Please select your City");
 return false;
 }
if( e != f ) {
alert("Password does not match");
 return false;
}
var atpos=d.indexOf("@");
var dotpos=d.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=d.length)
{
alert("Not a valid e-mail address");
return false;
} 


}
</script>

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){

//called when key is pressed in textbox
$("#contact").keypress(function (e)  
{ 
  //if the letter is not digit then display error and don't type anything
  if( e.which!=8 && e.which!=0 && (e.which<48 || e.which>57))
  {
    //display error message
    $("#errmsg").html("Number Only").show().fadeOut("slow"); 
    return false;
  } 
});


  });
  </script>

  </script>



    </head>
    <div id="fb-root"></div>
    <script>(function(d, s, id) {
        var js, fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id)) return;
        js = d.createElement(s); js.id = id;
        js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
        fjs.parentNode.insertBefore(js, fjs);
        }(document, 'script', 'facebook-jssdk'));</script>

    <script>(function(d, s, id) {
        var js, fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id)) return;
        js = d.createElement(s); js.id = id;
        js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
        fjs.parentNode.insertBefore(js, fjs);
        }(document, 'script', 'facebook-jssdk'));</script>
    <body>
        <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
        <script src=”js/bootstrap.js”></script>

            <div class="container well">
            <div class="navbar">
            <div class="navbar-inner">
            <div class="container">
            <ul class="nav">
            <li><img src="img/12.jpg"></a></li>
            <li class="active"><a href="index.html">Home</a></li>
            <li><a href="customization.html">Customization</a></li>
            <li><a href="error.php">Order Parts</a></li>
            <li><a href="inspiration.html">Inspiration Gallery</a></li>
            <li><a href="about.html">About us</a></li>
            <li><a href="loginuser.php">Login</a></li>
            </ul>
            </div>
            </div>
            </div>
            <div class="hero-unit">


<!-- Skitter Styles -->
<link href="css/skitter.styles.css" type="text/css" media="all" rel="stylesheet" />

<!-- Skitter JS -->
<script type="text/javascript" language="javascript" src="js/jquery-1.6.3.min.js">     </script>
<script type="text/javascript" language="javascript" src="js/jquery.easing.1.3.js">      </script>
<script type="text/javascript" language="javascript" src="js/jquery.animate-colors-      min.js"></script>
<script type="text/javascript" language="javascript"        src="js/jquery.skitter.min.js"></script>

<!-- Init Skitter -->
<script type="text/javascript" language="javascript">
    $(document).ready(function() {
        $('.box_skitter_large').skitter({
            theme: 'clean',
            numbers_align: 'center',
            progressbar: true, 
            dots: true, 
            preview: true
        });
    });
</script>
<style type="text/css">
 input[type=number]::-webkit-inner-spin-button, 
 input[type=number]::-webkit-outer-spin-button { 
-webkit-appearance: none; 
 margin: 0; 
 }
 </style>

 <br>
 <div style="width:400px; margin:0 auto; position:relative; border:3px solid      rgba(0,0,0,0); -webkit-border-radius:5px; -moz-border-radius:5px; border-radius:5px; -     webkit-box-shadow:0 0 18px rgba(0,0,0,0.4); -moz-box-shadow:0 0 18px rgba(0,0,0,0.4); box-         shadow:0 0 18px rgba(0,0,0,0.4); margin-top:20px; color:#FF0A0A;">
 <form id="form1" name="abc" method="post" action="addmem.php" onsubmit="return     validateForm()">
 <div style="background-color:#cccccc; font-family:Arial, Helvetica, sans-serif;      color:#000000; padding:5px; height:22px; width:390px;"> 


  <div style="float:left;"><strong>Members Registration</strong></div>
  <div style="float:right; margin-right:3px; background-color:#cccccc; width:25px;     text-align:center; height:22px;"><a href="loginuser.php">X</a></div>


  </div>
  <table width="368" align="center">
  <tr>
   <td colspan="2"><div style="font-family:Arial, Helvetica, sans-serif; font-    size:14px;"><font color="white">All Field Mark with asterisk (<span class="style1"><b>*</b>     </span>) must be filled up</div></td>
  </tr>
  <tr>
  <td colspan="2"><div style="font-family:Arial, Helvetica, sans-serif; color:#FF0000;     font-size:12px;"><?php
if( isset($_SESSION['ERRMSG_ARR']) && is_array($_SESSION['ERRMSG_ARR']) &&      count($_SESSION['ERRMSG_ARR']) >0 ) {
    echo '<ul class="err">';
    foreach($_SESSION['ERRMSG_ARR'] as $msg) {
        echo '<li>',$msg,'</li>'; 
    }
    echo '</ul>';
    unset($_SESSION['ERRMSG_ARR']);
}
  ?></div></td>
   </tr>
  <tr>
   <td width="120" valign="top"><div align="right"> <font color="#00EBFF">Firstname:     </div></td>
    <td width="236"><input type="text" name="firstname">
          <span class="style2">*</span></td>
  </tr>
          <tr>
            <td valign="top"><div align="right"><font color="#00EBFF">Lastname:</div>     </td>
            <td><input type="text" name="lastname">
              <span class="style2">*</span></td>
          </tr>

          <tr>
            <td valign="top"><div align="right"><font color="#00EBFF">Email:</div></td>
            <td><input type="text" name="email">
              <span class="style2">*</span></td>
          </tr>
          <tr>
            <td valign="top"><div align="right"><font color="#00EBFF">Password:</div>     </td>
            <td><input type="password" name="pword">
              <span class="style2">*</span></td>
          </tr>
          <tr>
            <td valign="top"><div align="right"><font color="#00EBFF">Retype Password:      </div></td>
            <td><input type="password" name="ambot">
              <span class="style2">*</span></td>
          </tr>
          <tr>
            <td valign="top"><div align="right"><font color="#00EBFF">Contact Number:      </div></td>
            <td><input name="number" type="number" min="0" id="contact" size="11">
                  <span style="font-family:Arial, Helvetica, sans-serif; font-     size:12px; color:#FF0000; font-weight:bold;" id="errmsg"></span><span class="style2">*     </span></td>
    </tr>
          <tr>
            <td valign="top"><div align="right"><font color="#00EBFF">Brgy. and House:     </div></td>
            <td><input type="text" name="house">
              <span class="style2">*</span></td>
          </tr>

    <tr>
            <td valign="top"><div align="right"><font color="#00EBFF">Street No:</div>     </td>
      <td><input type="text" name="street">
        <span class="style2">*</span></td>
  </tr>
          <tr>
         <!-- <tr><td align="right">City:</td><td><select name="city"      id="city">
                <option value="0">--Select One--</option>
                            <option value="1">Caloocan      City</option>
                            <option value="2">Las Pinas      City</option>
                            <option value="3">Makati      City</option>
                            <option value="4">Malabon          City</option>
                            <option          value="5">Mandaluyong City</option>
                            <option          value="6">Manila</option>
                            <option value="7">Marikina         City</option>
                            <option         value="8">Muntinlupa City</option>
                            <option         value="9">Navotas</option>
                            <option         value="10">Paranaque City</option>
                            <option value="11">Pasay         City</option>
                            <option value="12">Pasig     City</option>
                            <option     value="13">Pateros</option>
                            <option value="14">Quezon     City</option>
                            <option value="15">San     Juan</option>
                            <option     value="16">Taguig</option>
                            <option     value="17">Valenzuela City</option>

            </select><span class="style2">*</span></td></td></tr>-->
            <td valign="top"><div align="right"><font color="#00EBFF">City:</div></td>
            <td><select name="city"><option value="0">--Select One--</option>
                            <option value="Caloocan     City">Caloocan City</option>
                            <option value="Las Pinas     City">Las Pinas City</option>
                            <option value="Makati     City">Makati City</option>
                            <option value="Malabon     City">Malabon City</option>
                            <option value="Mandaluyong     City">Mandaluyong City</option>
                            <option     value="Manila">Manila</option>
                            <option value="Marikina     City">Marikina City</option>
                            <option value="Muntinlupa     City">Muntinlupa City</option>
                            <option     value="Navotas">Navotas</option>
                            <option value="Paranaque     City">Paranaque City</option>
                            <option value="Pasay     City">Pasay City</option>
                            <option value="Pasig     City">Pasig City</option>
                            <option     value="Pateros">Pateros</option>
                            <option value="Quezon     City">Quezon City</option>
                            <option value="San     Juan">San Juan</option>
                            <option     value="Taguig">Taguig</option>
                            <option value="Valenzuela     City">Valenzuela City</option></select>
              <span class="style2">*</span></td>
          </tr>
 <tr>
            <td valign="top">&nbsp;</td>
            <td><input type="submit" value="Save"></td>
  </tr>
</table>

  </form>
  </div>
  <hr>
                    <div class="footer">
                    <p>Copyright &copy; Athan Motorcycle</p>
                    </div>



    </body>
 </html>

and this is my code where it will redirect after pressing the button of registration:

<?php
session_start();
$errmsg_arr = array();
$errflag = false;
include('config.php');


$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$email=$_POST['email'];
$pword=$_POST['pword'];
$number=$_POST['number'];
$house=$_POST['house'];
$street=$_POST['street'];
$city=$_POST['city'];

$min_length = 6;  
// you can set minimum length of the query if you want  
 if(strlen($pword) >= $min_length){

mysql_query("INSERT INTO athan_members (firstname, lastname, email, number, house1,     street1, city, password) VALUES ('$firstname', '$lastname', '$email', '$number', '$house',     '$street', '$city', '$pword')");
header("location: loginuser.php");
}
else
{
$errmsg_arr[] = 'password must contain not less than 6 characters';
$errflag = true;
}


if($errflag) {
    $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
    session_write_close();
    header("location: new.php");
    exit();
}




mysql_close($con);
?> 

I have the idea but i don't know where to put it :3

Answers


modify your mysql query like INSERT ... ON DUPLICATE KEY UPDATE

mysql_query("INSERT INTO athan_members (firstname, lastname, email, number, house1,     street1, city, password) VALUES ('$firstname', '$lastname', '$email', '$number', '$house',     '$street', '$city', '$pword') ON DUPLICATE KEY UPDATE")

and declare email as UNIQUE in atha_members table


Need Your Help

Java Instance Variable Accessibility

java inheritance variables accessibility

What is the difference in the accessibility of the following variables in Java?

HowTo for newbie: Managing currency in iPhone app

iphone objective-c

I'm building a app that need manage money datatype.