직원을 추가하기 만하면 직원 ID도 증가합니다. 또한 텍스트 상자는자동 증분 직원 ID
또한 여기 내 코드의 비활성화해야합니다. 내가 원하는 것은 새 직원을 추가 할 때 직원 ID를 자동으로 증가시키는 것입니다. 모두가 나를 도울 수 있기를 바랍니다. 미리 감사드립니다. :)
<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 INTO 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>
EmpID INT NOT NULL AUTO_INCREMENT PRIMARY KEY – Prasad
에 이러한 쿼리를 추가합니다. 자동 증가로 설정하면 데이터베이스에 실제로 행을 만들 때까지 키가 무엇인지 알 수 없습니다. 테이블의 기본 키가되도록하려면 사용자가 테이블의 기본 키를 볼 필요가 없습니다. ID는 숫자가 아니더라도 실제로는 숫자가 아니므로 일종의 선행 문자가 필요합니다. –
답변 해 주셔서 감사합니다. 정말 고맙지 만 내 코드를 편집 할 수 있습니까? 그것을 시각화하기 위해? 미리 감사드립니다. :) –