How to handle SQLSTATE[23000]: Integrity constraint violation: 1062
<p>Everything is working in my code however if your going to create a user it will accept even if you create a multiple user with same email I already tried to search some solution and put it in my code but still I can't make it work and how can i make the SQLSTATE[23000]: Integrity constraint violation: 1062 change into "error email already exist" ? is it possible?</p>

<p>addform.php</p>

<p>and I also want to display an error message if there is a duplicate </p>

<pre><code>&lt;style type="text/css"&gt;
#dis{
display:none;
}
&lt;/style&gt;




&lt;div id="dis"&gt;
&lt;!-- here message will be displayed --&gt;
&lt;/div&gt;


 &lt;form method='post' id='emp-SaveForm' action="#"&gt;

&lt;table class='table table-bordered'&gt;

    &lt;tr&gt;
        &lt;td&gt;First Name&lt;/td&gt;
        &lt;td&gt;&lt;input type='text' name='fname' class='form-control'  required /&gt;&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
        &lt;td&gt;Last Name&lt;/td&gt;
        &lt;td&gt;&lt;input type='text' name='lname' class='form-control'  required&gt;&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
        &lt;td&gt;Contact Number&lt;/td&gt;
        &lt;td&gt;&lt;input type='number' name='contactnum' class='form-control'  required&gt;&lt;/td&gt;
    &lt;/tr&gt;

     &lt;tr&gt;
        &lt;td&gt;Email&lt;/td&gt;
        &lt;td&gt;&lt;input type='email' name='email' class='form-control' required /&gt;&lt;/td&gt;
    &lt;/tr&gt;

     &lt;tr&gt;
        &lt;td&gt;Password&lt;/td&gt;
        &lt;td&gt;&lt;input type="password" name='pass' class='form-control'  required /&gt;&lt;/td&gt;
    &lt;/tr&gt;

     &lt;tr&gt;
        &lt;td&gt;Language&lt;/td&gt;
        &lt;td&gt;&lt;input type='text' name='lang' class='form-control'  required /&gt;&lt;/td&gt;
    &lt;/tr&gt; 
    &lt;tr&gt;
        &lt;td colspan="2"&gt;
        &lt;button type="submit" class="btn btn-primary" name="btn-save" id="btn-save"&gt;
        &lt;span class="glyphicon glyphicon-plus"&gt;&lt;/span&gt; Save this User
        &lt;/button&gt;  
        &lt;/td&gt;
    &lt;/tr&gt;

&lt;/table&gt;
</code></pre>

<p></p>

<p>create.php</p>

<pre><code>&lt;?php
require_once 'dbconfig.php';


if($_POST)
{
    $fname = $_POST['fname'];
    $lname = $_POST['lname'];
    $contactnum = $_POST['contactnum'];
    $email = $_POST['email'];
    $pass = $_POST['pass'];
    $lang = $_POST['lang'];
    try{

        $stmt = $db_con-&gt;prepare("INSERT INTO tbluser(fname,lname,contactnum,email,pass,lang) VALUES(:ufname,:ulname,:ucontact,:uemail,:upass,:ulang)");
        $stmt-&gt;bindParam(":ufname", $fname);
        $stmt-&gt;bindParam(":ulname", $lname);
        $stmt-&gt;bindParam(":ucontact", $contactnum);
        $stmt-&gt;bindParam(":uemail", $email);
        $stmt-&gt;bindParam(":upass", $pass);
        $stmt-&gt;bindParam(":ulang", $lang);
        if($stmt-&gt;execute())
        {
            echo "Successfully Added";
        }
        else{
            echo "Query Problem";
        }   
    }
    catch(PDOException $e){
        echo $e-&gt;getMessage();
    }
}

?&gt;
</code></pre>

<p>I'm just new in php  I'm using PDO in database don't know if its a good thing anyway thanks for the help and please let me know if I can use or just copy paste your code or not :)</p>