我有一个包含人员 ID、姓名、部门、报告 ID、描述、日期的数据库
所以每次我插入描述时,我都想在数据库中自动生成一个reportID。那么我该怎么做呢?假设我有以下代码:
管理项.php
<body>
<form id="btn" name="insert" method="POST" action="insertadmin.php" onSubmit="return
validate();">
<table id="description" width="50%" border="0" cellpadding="1" cellspacing="0">
<input type="hidden" name="hidden" id="hiddenField">
<tr><td>Enter your description inside the box:</td></tr>
<tr><td><textarea name="description" value="" rows="10" cols="53"></textarea></td></tr>
<tr><td><a href="http://localhost/kinhock/viewadmindb.php"> View Admin</a></td>
<td> <a href="http://localhost/kinhock/viewemployeedb.php"> View Employee</a></td>
<td> <a href="http://localhost/kinhock/viewreportdb.php"> View Report </a></td>
<td> <input id='btn'type='submit'
name='Submit' value='Submit' /></td>
<td> <a href="http://localhost/kinhock/adminlogin.php"> Logout </a></td></tr>
</table>
</form>
</body>
插入管理员.php
<?php
session_start();
include('adminconfig.php');
$session=$_SESSION['userID'];
$name=$_SESSION['name'];
$department=$_SESSION['department'];
$desc=$_POST['description'];
$name_arr=array();
$dept_arr=array();
$desc_arr=array();
$i = -1;
++$i;
$desc_arr[$i]= $_POST['description'];
$j=0;
while ( $j <= $i)
{
$desc = $desc_arr[$i];
$sql = "INSERT INTO `employee`. `report` (ID ,name ,department ,description)VALUES
('$session' ,'$name' ,'$department' ,'$desc'
)";
++$j;
$result = mysql_query($sql);
if(!$result){
die('invalid query:'.mysql_error());
}
else
?>
<p style="font-family:arial;color:#0066CC;font-size:30px;">Data added
succesfully...
</p>
<?php
header('Refresh:3; url=adminitem.php');
die;
}
?>