<?php
include("connect.php");

$query = "SELECT StaffID, StaffNum FROM staff ORDER BY StaffNum DESC LIMIT 1";
$result = $db->query($query);

$row = $result->fetch_array();
$StaffID = $row["StaffID"];
list($one[0],$one[1]) = split('A',$StaffID);

$index = ++$one[1];
$StaffNum = $index;

if($index < 10)
{
	$index = "A00".$index;
}
else if($index < 100)
{
	$index = "A0".$index;
}
else if ($index < 1000)
{
	$index = "A".$index;
}
else
{
	$index = "Your CODE field is full!";
}

echo "<input type='hidden' name='StaffID' value='".$index."'><input type='hidden' name='StaffNum' value='".$StaffNum."'>".$index;
?>