php - Auto increment employee ID -
i want add employee , after that, employee id increment. textbox must disabled
also here's code. want auto increment employee id when add new employee. hope me. thank in advance. :)
<center> <form class="contact_form" action="#" method="post"> <h2>register new employee</h2> <br/> <table> <tr> <td><label for="emp">emp id:</label></td> <td><input type="text" name="emp" placeholder="emp id" required /></td> </tr> <tr> <td><label for="name">name:</label></td> <td><input type="text" name="fname" placeholder="first name" required /> <input type="text" name="lname" placeholder="last name" required /></td> </tr> <tr> <td><label for="address">address:</label></td> <td><input type="text" name="address" placeholder="full address" required /></td> </tr> <tr> <td><label for="contact">contact:</label></td> <td><input type="text" name="contact" placeholder="contact number" required /></td> </tr> <tr> <td><label for="type">type:</label></td> <td><select name="type" id="type"> <option>type of employee</option> <option>contractual</option> <option>regular</option> </select> </td> </tr> <tr> <td><label for="salary">salary:</label></td> <td><input type="text" name="salary" placeholder="emp salary" required /></td> </tr> </table> <br/> <button class="submit" name="submit" type="submit" onclick="message()">submit</button> <button class="reset" name="reset" type="reset">clear</button> </form> <?php if (isset($_post['submit'])) { include 'alqdb.php'; $emp=$_post['emp']; $fname= $_post['fname']; $lname=$_post['lname']; $address=$_post['address']; $contact=$_post['contact']; $type=$_post['type']; $salary=$_post['salary']; mysqli_query($con, "insert employee (empid,empfname,emplname,empaddress,contactnumber,typeofemployee,salary) values ('$emp','$fname','$lname','$address','$contact','$type','$salary')"); } ?> </center> </body> <script language="javascript"> function message() { alert("successfully added!"); } </script>
if want have empid emp001
this code work:
public function autoincemp()
{ global $value2; $query = "select empid tbemployee order empid desc limit 1"; $stmt = $this->db->prepare($query); $stmt->execute(); if ($stmt->rowcount()>0) { $row=$stmt->fetch(pdo::fetch_assoc); $value2 =$row['empid']; $value2 =substr($value2,3,5); $value2 = (int)$value2 + 1; $value2 = "emp". sprintf('%04s',$value2); $value = $value2; return $value; } else { $value2 = "emp0001"; $value = $value2; return $value; } }
Comments
Post a Comment