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. ERROR
Warning: A non-numeric value encountered
I need a result to be E-0000001 when the forms loaded after the order complete next order need be increment as E-0000002 increment by 1
<?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);
}
?>
<?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";
}
}
}
?>
<html>
<head>
<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">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</head>
<body>
<div class="row">
<div class="col-sm-4">
<form action="<?php echo($_SERVER["PHP_SELF"]); ?>" method="post">
<div align="left">
<h3>Auto No in Php</h3>
</div>
<div align="left">
<label>Employee No</label>
<input type="text" class="form-control" name="id" id="id" style="color: blue" value="<?php echo $number; ?>" readonly >
</div>
<div align="left">
<label>Employee Name</label>
<input type="text" class="form-control" name="ename" id="ename" >
</div>
<div align="left">
<label>Employee Salary</label>
<input type="text" class="form-control" name="sal" id="sal" >
</div>
</br>
<div align="left">
<input type="submit" value="ADD" class="btn btn-success">
</div>
</form>
</div>
</div>