重复输入的数据库错误

I have a proper db connection where the database name is db-name,the table name is tb-name and the field names are same as the form fields: name, phone, form no, address.

I would like to avoid duplicated form entries with the same "form no", if that happen I would like to show an error and show the form again.

Please help me, thanks.

        <div class="cform">
          <center>
            <h2>New Water Meter Application Form</h2>
          </center>
          <form action="submit.php<?php if($formId != ''){ echo '?update='.$formId; } ?>" method="post" name="myform" class="compform" id="myform">
           <input type="hidden" name="UserName" value="<?php echo $_SESSION['UserName']; ?>" />
           <ul>
             <div class="part1">
               <li>
                 <p>name:</p>
                 <input type="text" name="name" id="name"   />
               </li>
               <li>
                 <p>phone:</p>
                 <input type="text" name="phone" id="phone" /> 
               </li>
               <li>
                 <p>Form No.:</p>
                 <input type="text" name="FormNo" id="FormNo"  />
               </li>
               <li>
                 <p>address:</p>
                 <input type="text" name="address" id="address" /> 
               </li>
             </ul>
             <input type="Submit" name="submit" id="Submit" value="submit" class="submit"  />
          </form>

Try to implement your INSERT Query should be like this. I hope it is helpful

INSERT INTO TABLE_NAME
(name, phone, FormNo, address)
VALUES('MyName', '123132', '5', 'xyz xyz')
WHERE FormNo != (SELECT FormNo FROM TABLE_NAME)

Or If

SELECT FormNo FROM TABLE_NAME WHERE FormNo = "5"

Then Return Error Message then Entry Available. Else

INSERT INTO TABLE_NAME
(name, phone, FormNo, address)
VALUES('MyName', '123132', '5', 'xyz xyz')