title: How to Generate invoice number using php
body: <p>I need to generate the invoice number from table with auto increment ID.this is code i tried but when the form is loaded invoice number shown error.
  <strong>ERROR</strong></p>
  
  <blockquote>
    <p>Warning: A non-numeric value encountered</p>
  </blockquote>
  
  <p>I need a result to be  <strong>E-0000001</strong> when the forms loaded after the order complete next order need be increment as  <strong>E-0000002</strong> increment by 1</p>
  
  <pre><code> &lt;?php
   $query = "SELECT id, CONCAT( 'E-', LPAD(id,7,'0') ) FROM employee";
   $result = mysqli_query($conn,$query);
   $row = mysqli_fetch_array($result);
   $lastid = $row['id'];
  
  $number = "F-". $lastid;
   if($lastid == " ")
   {
       $number = "E-0000001";
   }
   else
  {
      $number = "E-" . ($number + 1);
  }
  
  ?&gt;
  
  &lt;?php
  
      if($_SERVER["REQUEST_METHOD"]== "POST")
      {
          $id = $_POST['id'];
          $ename = $_POST['ename'];
          $sal = $_POST['sal'];
  
          if(!$conn)
          {
              die("connection failed " . mysqli_connect_error());
          }
          else
          {
              $sql = "insert into employee(id,ename,salary)VALUES('$id','$ename','$sal') ";
  
              if(mysqli_query($conn,$sql))
  
              {
                  echo "Record ADDEDDDDDDD";
  
              }
              else
              {
  
                  echo "Record Faileddd";
              }
  
  
          }
  
      }
  
  ?&gt;
  
  &lt;html&gt;
  
  &lt;head&gt;
      &lt;link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"&gt;
      &lt;script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"&gt;&lt;/script&gt;
      &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"&gt;&lt;/script&gt;
      &lt;script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"&gt;&lt;/script&gt;
  
  &lt;/head&gt;
  
  &lt;body&gt;
  
  &lt;div class="row"&gt;
      &lt;div class="col-sm-4"&gt;
          &lt;form action="&lt;?php echo($_SERVER["PHP_SELF"]); ?&gt;" method="post"&gt;
              &lt;div align="left"&gt;
                  &lt;h3&gt;Auto No in Php&lt;/h3&gt;
              &lt;/div&gt;
  
              &lt;div align="left"&gt;
                  &lt;label&gt;Employee No&lt;/label&gt;
                  &lt;input type="text" class="form-control" name="id" id="id" style="color: blue" value="&lt;?php echo $number; ?&gt;" readonly &gt;
              &lt;/div&gt;
  
  
              &lt;div align="left"&gt;
                  &lt;label&gt;Employee Name&lt;/label&gt;
                  &lt;input type="text" class="form-control" name="ename" id="ename"  &gt;
              &lt;/div&gt;
  
  
              &lt;div align="left"&gt;
                  &lt;label&gt;Employee Salary&lt;/label&gt;
                  &lt;input type="text" class="form-control" name="sal" id="sal" &gt;
              &lt;/div&gt;
  
              &lt;/br&gt;
  
              &lt;div align="left"&gt;
                  &lt;input type="submit" value="ADD" class="btn btn-success"&gt;
              &lt;/div&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  
  &lt;/div&gt;
  </code></pre>