我只想添加一个员工,之后员工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实际上不是一个数字(即使它是一串数字),所以您通常需要某种主角。 –
谢谢你的回答。我真的很感激,但你能编辑我的代码吗?想象它?先谢谢你。 :) –