title: Cannot insert explicit value for identity column in table when IDENTITY_INSERT is set to OFF
body: <p>there's an error saying "Cannot insert explicit value for identity column in table  when IDENTITY_INSERT is set to OFF." what is the possible solution to this problem? I am using SQL server 2014 and php</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;style&gt;
   th{text-align: right; border-style: none;}
   td{
    width: 10%;
   }
   table{border-spacing:15px; width:20%;}
   .button {
      background-color: black;
      border: none;
      color: white;
      padding: 15px 32px;
      text-align: center;
      text-decoration: none;
      display: inline-block;
      font-size: 16px;
      margin: 4px 2px;
      cursor: hand;
   border-radius:12px;
   }
   .button:hover{
    background-color: grey;
    color: black;
   }
   input[type=number]{
      width:200px;
   }
   input[type=date]{
   width: 200px;
   }
   input[type=number]::-webkit-inner-spin-button, 
   input[type=number]::-webkit-outer-spin-button { 
   -webkit-appearance: none; 
   margin: 0; 
   }
   
  &lt;/style&gt;
  &lt;center&gt;
  &lt;form action="" method="POST" enctype="multipart/form-data"&gt;
  &lt;head&gt;
  &lt;script language="javascript" type="text/javascript"&gt;
  function removeSpaces(string) {
   return string.split(' ').join('');
  }
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;table frame=box&gt;
  &lt;tr&gt;&lt;td colspan=5&gt;&lt;b&gt;&lt;center&gt;&lt;font size=6&gt;CUSTOMER PROFILE&lt;/font&gt;&lt;/center&gt;&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;th&gt;REC NUMBER:&lt;/th&gt;&lt;td&gt;&lt;input type=number name="rec_no"&gt;&lt;/td&gt;&lt;th&gt;CUSTOMER ID:&lt;/th&gt;&lt;td&gt;&lt;input type=text name="cust_ID" size=24 required&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;th&gt;CUSTOMER NAME:&lt;/th&gt;&lt;td&gt;&lt;Input type=text name="cust_name" size=24  required&gt;&lt;/td&gt;&lt;th&gt;SEC-REGISTERED NAME:&lt;/th&gt;&lt;td&gt;&lt;input type=text name="secname" size=24 required&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;th&gt;TIN NUMBER:&lt;/th&gt;&lt;td&gt;&lt;input type=number name="tin"  min="100000000" max="999999999" required&gt;&lt;/td&gt;
  &lt;td&gt;&lt;select name="store_type"&gt;
  &lt;option value=""&gt;STORE TYPE&lt;/option&gt;
  &lt;option value=""&gt;--&lt;/option&gt;
  &lt;option value=""&gt;--&lt;/option&gt;&lt;/td&gt;
  &lt;/select&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td colspan=2&gt;&lt;b&gt;&lt;u&gt;&lt;font size=5&gt;ORGANIZATION AND BUSINESS:&lt;/font&gt;&lt;/b&gt;&lt;/u&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;th&gt;SIZE OF BUSINESS:&lt;/th&gt;&lt;td&gt;&lt;input type=text name="size_business" placeholder="(Last FY Average)"  size=24 required&gt;&lt;/td&gt;&lt;th&gt;SELLER ID:&lt;/th&gt;&lt;td&gt;&lt;input type="number" name="seller_id" min="1" max="12" required&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;!--&lt;/td&gt;--&gt;
  &lt;tr&gt;&lt;th&gt;DATE OF ESTABLISHMENT:&lt;/th&gt;&lt;td&gt;&lt;input type="date" name="date_established" min="01-01-1900" required&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;th&gt;ADDRESS(Headquarters):&lt;/th&gt;&lt;td&gt;&lt;input type="text" name="street" placeholder="House Number/Street" size=24 onblur="this.value=removeSpaces(this.value);" required&gt;&lt;/td&gt;&lt;td&gt;&lt;input type=text name="barangay" placeholder="Barangay"  size=24 required&gt;&lt;/td&gt;&lt;td&gt;&lt;input type=text name="city" placeholder="City / Municipality" size=24 onblur="this.value=removeSpaces(this.value);" required&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;th&gt;&amp;nbsp&lt;/th&gt;&lt;td&gt;&lt;input type=text name="province" placeholder="Province" size=24 onblur="this.value=removeSpaces(this.value);"&gt;&lt;/td&gt;&lt;td&gt;&lt;input type=number name="postal_code" placeholder="Postal Code" min="1000" max="9999"&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;th&gt;TELEPHONE# / FAX:&lt;/th&gt;&lt;td&gt;&lt;input type=text name="tel_num" required&gt;&lt;/td&gt;&lt;th&gt;PAYMENT TERMS:&lt;/th&gt;&lt;td&gt;&lt;input type=text name="payment_terms" size=24&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;th&gt;SHIPPING INSTRUCTIONS:&lt;/th&gt;&lt;td colspan=3&gt;&lt;input type=text name="shipping_inst" size=90&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;th&gt;NUMBER OF DOORS:&lt;/th&gt;&lt;td&gt;&lt;input type=text name="doors_num" size=24&gt;&lt;/td&gt;&lt;th&gt;NUMBER OF WAREHOUSES:&lt;/th&gt;&lt;td&gt;&lt;input type=text name="warehouse_num" size=24&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td colspan=2&gt;&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp &lt;b&gt;&lt;u&gt;&lt;font size=5&gt;CONTACT PERSONNEL:&lt;/font&gt;&lt;/b&gt;&lt;/u&gt;&lt;/td&gt;&lt;td&gt;&amp;nbsp &lt;/td&gt;&lt;td&gt;Birthday:&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;th&gt;OWNER:&lt;/th&gt;&lt;td&gt;&lt;input type=text name="owner_name" size=24 &gt;&lt;/td&gt;&lt;td&gt;&lt;input type=number name="owner_contact" size=24 placeholder="Contact Number"&gt;&lt;/td&gt;&lt;td&gt;&lt;input type=date name="owner_bday" placeholder="Date of Birth" size=23&gt;&lt;/td&gt;&lt;td&gt;&lt;input type=text name="owner_interest" placeholder="Interest"&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;th&gt;PURCHASER/S:&lt;/th&gt;&lt;td&gt;&lt;input type=text name="purch_name" size=24 &gt;&lt;/td&gt;&lt;td&gt;&lt;input type=number name="purch_contact" placeholder="Contact Number"&gt;&lt;/td&gt;&lt;td&gt;&lt;input type=date name="purch_bday" placeholder="Date of Birth" size=23 &gt;&lt;/td&gt;&lt;td&gt;&lt;input type=text name="purch_interest" placeholder="Interest"&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;th&gt;&amp;nbsp&amp;nbspACCOUNTING HEAD:&lt;/th&gt;&lt;td&gt;&lt;input type=text name="acc_name" size=24 &gt;&lt;/td&gt;&lt;td&gt;&lt;input type=number name="acc_contact" placeholder="Contact Number"&gt;&lt;/td&gt;&lt;td&gt;&lt;input type=date name="acc_bday" placeholder="Date of Birth" size=23&gt;&lt;/td&gt;&lt;td&gt;&lt;input type=text name="acc_interest" placeholder="Interest"&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;th&gt;WAREHOUSE HEAD:&lt;/th&gt;&lt;td&gt;&lt;input type=text name="wh_name" size=24 &gt;&lt;/td&gt;&lt;td&gt;&lt;input type=number name="wh_contact" placeholder="Contact Number"&gt;&lt;/td&gt;&lt;td&gt;&lt;input type=date name="wh_bday" placeholder="Date of Birth" size=23&gt;&lt;/td&gt;&lt;td&gt;&lt;input type=text name="wh_interest" placeholder="Interest"&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;th&gt;OTHER PERSONNEL:&lt;/th&gt;&lt;td&gt;&lt;input type=text name="other_name" size=24 &gt;&lt;/td&gt;&lt;td&gt;&lt;input type=number name="other_contact" placeholder="Contact Number"&gt;&lt;/td&gt;&lt;td&gt;&lt;input type=date name="other_bday" placeholder="Date of Birth" size=23&gt;&lt;/td&gt;&lt;td&gt;&lt;input type=text name="other_interest" placeholder="Interest"&gt;&lt;/td&gt;&lt;/tr&gt;
  
  &lt;tr&gt;&lt;td colspan=2&gt;&lt;b&gt;&lt;u&gt;&lt;font size=5&gt;TERMS AND DISCOUNTS:&lt;/font&gt;&lt;/b&gt;&lt;/u&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;th&gt;PAYMENT TERMS:&lt;/th&gt;&lt;td&gt;&lt;input type=text name="payment_terms2" size=24 &gt;&lt;/td&gt;&lt;th&gt;COLLECTION SCHEDULE:&lt;/th&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;th&gt;DISCOUNT:&lt;/th&gt;&lt;td&gt;&lt;input type=text name="discount" size=24 &gt;&lt;/td&gt;&lt;td colspan=2&gt;&lt;input type=text name="coll_sched" size="50" placeholder="e.g Every Wednesday after lunch, MWF Mornings"  &gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td colspan=2&gt;&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp &lt;b&gt;&lt;u&gt;&lt;font size=5&gt;BUSINESS GOALS:&lt;/font&gt;&lt;/b&gt;&lt;/u&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;th&gt;VOLUME:&lt;/th&gt;&lt;td&gt;&lt;input type=text name="volume" size=24 &gt;&lt;/td&gt;&lt;th&gt;CSL:&lt;/th&gt;&lt;td&gt;&lt;input type=text name="csl" size=23&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;th&gt;MERCHANDISING:&lt;/th&gt;&lt;td&gt;&lt;input type=text name="merchandising" size=24 &gt;&lt;/td&gt;&lt;th&gt;ASSORTMENT:&lt;/th&gt;&lt;td&gt;&lt;input type=text name="assortment" size=23&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;th&gt;VEHICLE:&lt;/th&gt;&lt;td&gt;&lt;input type=text name="vehicle" size=24 &gt;&lt;/td&gt;&lt;th&gt;PRICING:&lt;/th&gt;&lt;td&gt;&lt;input type=text name="pricing" size=23&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;th&gt;DISTRIBUTION:&lt;/th&gt;&lt;td&gt;&lt;input type=text name="distribution" size=24 &gt;&lt;/td&gt;&lt;th&gt;MARGIN:&lt;/th&gt;&lt;td&gt;&lt;input type=text name="margin" size=23 placeholder="Customer Profitability"&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td colspan=2&gt;&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp &lt;b&gt;&lt;u&gt;&lt;font size=5&gt;STRATEGIES:&lt;/font&gt;&lt;/b&gt;&lt;/u&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;th&gt;PRICE:&lt;/th&gt;&lt;td&gt;&lt;input type=text name="price" size=24 &gt;&lt;/td&gt;&lt;th&gt;PEOPLE:&lt;/th&gt;&lt;td&gt;&lt;input type=text name="people" size=23&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;th&gt;PROMOTION:&lt;/th&gt;&lt;td&gt;&lt;input type=text name="promotion" size=24 &gt;&lt;/td&gt;&lt;th&gt;PRODUCT:&lt;/th&gt;&lt;td&gt;&lt;input type=text name="product" size=23&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;th&gt;PLACE:&lt;/th&gt;&lt;td&gt;&lt;input type=text name="place" size=24 &gt;&lt;/td&gt;&lt;th&gt;OTHERS:&lt;/th&gt;&lt;td&gt;&lt;input type=text name="others" size=23&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;th&gt;CATMAN ENROLLMENT:&lt;/th&gt;&lt;td&gt;&lt;input type=text name="catman" size=24 &gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td colspan=2&gt;&lt;font size=5&gt;&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp &lt;b&gt;&lt;u&gt;POLICIES:&lt;/u&gt;&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;th&gt;REPLENISHMENT ORDERS:&lt;/th&gt;&lt;td colspan=3&gt;&lt;input type=text name="rep_orders" size=92&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;th&gt;ASSORTMENT/MERCHANDISING:&lt;/th&gt;&lt;td colspan=3&gt;&lt;input type=text name="assort_merch" size=92&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;th&gt;NEW PRODUCTS:&lt;/th&gt;&lt;td colspan=3&gt;&lt;input type=text name="new_prod" size=92&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;th&gt;PRICING/PROMOTION:&lt;/th&gt;&lt;td colspan=3&gt;&lt;input type=text name="price_promote" size=92&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;th&gt;UPLOAD PICTURE:&lt;/th&gt;&lt;td colspan=2&gt;&lt;input type=file name="image" size=92&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;/table&gt;
  &lt;input type="submit" class="button" name="submit" value="Submit"&gt;
  &lt;input type="button" value="Cancel" class="button" onclick="window.location.href='page_accounting.php'"&gt;
  &lt;/form&gt;
  &lt;?php
  if (isset($_POST['submit']))
  {
  $serverName = "QWERTY-PC\SQLEXPRESS";
  $connectionInfo = array( "Database"=&gt;"customerdb", "UID"=&gt;"dbadmin", "PWD"=&gt;"qwerty" );
  $conn = sqlsrv_connect( $serverName, $connectionInfo);
  if( $conn === false ) {
       die( print_r( sqlsrv_errors(), true));
  }
   
   $street = $_POST['street'];
   $barangay = $_POST['barangay'];
   $city = $_POST['city'];
   $province = $_POST['province'];
  
   $address = $street .'+'. $barangay .'+'.$city .'+'.$province;
   $url = "http://maps.google.com/maps/api/geocode/json?address=$address&amp;sensor=false&amp;region=Philippines";
   $response = file_get_contents($url);
   $response = json_decode($response, true);
   //print_r($response);
   $lat = $response['results'][0]['geometry']['location']['lat'];
   $long = $response['results'][0]['geometry']['location']['lng'];
  
  $rec_no = $_POST['rec_no'];
  $cust_ID = $_POST['cust_ID'];
  $cust_name = $_POST['cust_name'];
  $secname = $_POST['secname'];
  $tin = $_POST['tin'];
  $store_type = $_POST['store_type'];
  $size_business = $_POST['size_business'];
  $date_established = $_POST['date_established'];
  $seller_id = $_POST['seller_id'];
  $street = $_POST['street'];
  $barangay = $_POST['barangay'];
  $city = $_POST['city'];
  $province = $_POST['province'];
  $tel_num = $_POST['tel_num'];
  $payment_terms = $_POST['payment_terms'];
  $shipping_inst = $_POST['shipping_inst'];
  $doors_num = $_POST['doors_num'];
  $warehouse_num = $_POST['warehouse_num'];
  $owner_name = $_POST['owner_name'];
  $owner_contact = $_POST['owner_contact'];
  $owner_bday = $_POST['owner_bday'];
  $owner_interest = $_POST['owner_interest'];
  $purch_name = $_POST['purch_name'];
  $purch_contact = $_POST['purch_contact'];
  $purch_bday = $_POST['purch_bday'];
  $purch_interest = $_POST['purch_interest'];
  $acc_name = $_POST['acc_name'];
  $acc_contact = $_POST['acc_contact'];
  $acc_bday = $_POST['acc_bday'];
  $acc_interest = $_POST['acc_interest'];
  $wh_name = $_POST['wh_name'];
  $wh_contact = $_POST['wh_contact'];
  $wh_bday = $_POST['wh_bday'];
  $wh_interest = $_POST['wh_interest'];
  $other_name = $_POST['other_name'];
  $other_contact = $_POST['other_contact'];
  $other_bday = $_POST['other_bday'];
  $other_interest = $_POST['other_interest'];
  $payment_terms2 = $_POST['payment_terms2'];
  $discount = $_POST['discount'];
  $coll_sched = $_POST['coll_sched'];
  $volume = $_POST['volume'];
  $csl = $_POST['csl'];
  $merchandising = $_POST['merchandising'];
  $assortment = $_POST['assortment'];
  $vehicle = $_POST['vehicle'];
  $pricing = $_POST['pricing'];
  $distribution = $_POST['distribution'];
  $margin = $_POST['margin'];
  $price = $_POST['price'];
  $people = $_POST['people'];
  $promotion = $_POST['promotion'];
  $product = $_POST['product'];
  $place = $_POST['place'];
  $others = $_POST['others'];
  $catman = $_POST['catman'];
  $rep_orders = $_POST['rep_orders'];
  $assort_merch = $_POST['assort_merch'];
  $new_prod = $_POST['new_prod'];
  $price_promote = $_POST['price_promote'];
  $name= $_FILES['image']['name'];
  $image= $_FILES['image']['tmp_name'];
  $imageType = $_FILES['image']['type'];
  $image = file_get_contents($image);
  $image = base64_encode($image);
  
  $sql = "INSERT INTO Customer_Details (Rec_No, Cust_ID, Cust_Name, SEC_Name, Store_Type,[TIN Number],[Date of Establishment],[Size of Business],Seller_ID,Latitude, Longitude, [Telephone/Fax],[Payment Terms],[Shipping Instructions],[Number of Doors],[Number of Warehouses],Owner,[Purchaser(s)],[Accounting Head],[Warehouse Head],[Other Personnel],[Payment Terms 2],Discount,[Collection Schedule],Volume,CSL,[Marketing Vehicle],Distribution, Assortment,Merchandising, Pricing,Margin,Price,Promotion,People,Others,[Catman Enrollment],[Replenishment Orders],[Assortment/Merchandising],[New Products],[Pricing/Promotions], image, street, barangay, city, province) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
  $params = array($rec_no, $cust_ID, $cust_name, $secname, $store_type, $tin, $date_established, $size_business, $seller_id, $lat, $long, $tel_num, $payment_terms, $shipping_inst, $doors_num, $warehouse_num,$owner_name,$purch_name,$acc_name,$wh_name,$other_name,$payment_terms2,$discount,$coll_sched,$volume,$csl,$vehicle,$distribution,$assortment,$merchandising,$pricing,$margin,$price,$promotion,$people,$others,$catman,$rep_orders,$assort_merch,$new_prod,$price_promote, $image, $street, $barangay, $city, $province);
  /*$sql2 = "INSERT INTO Customer_Master (Cust_ID, Internal_ID, Address1, Address2, City, Company_ID) VALUES (?, ?, ?, ?, ?, ?)";
  $params2 = array($cust_ID, $seller_id, $street, $barangay, $city, $tin);
  */
  $stmt = sqlsrv_query($conn, $sql, $params);
  /*O$stmt = sqlsrv_query($conn, $sql2, $params2);*/
  if( $stmt === false ) {
       die( print_r( sqlsrv_errors(), true));
  }
  }
  ?&gt;</code></pre>
  </div>
  </div>
  </p>