title: How to prevent duplicate value in PDO
body: <p>I want to restrict duplicate value, How could I do.</p>
  <pre class="lang-php prettyprint-override"><code>if($_GET[&quot;data&quot;] == &quot;add_class&quot;){
  
              $name = $_POST[&quot;txtName&quot;];
              $sql = &quot;Insert into tbl_class (class_name) values (:class_name);&quot;;
              $insert = $conn-&gt;prepare($sql);
              $insert-&gt;bindParam(':class_name', $name);
  
              if($insert-&gt;execute()){
                     echo json_encode(&quot;Insert Success&quot;);}
              else{ 
                     echo json_encode(&quot;Insert Faild&quot;);}    
      }
  </code></pre>