I have a table in the database contains ID which is the primary key and auto incremented, and RFC the RFC should be auto incremented as well like RFC-0001 then RFC-0002 but on the HTML/PHP part for some reason I'm doing something wrong and I dont know how to fix it any ideas ? this is my database table
and this is my php html code
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "change";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>
<?php
$try="select * from test order by id desc limit1";
$result= mysqli_query($conn,$try);
$row=mysqli_fetch_array($result);
$lastid= $row['rfc'];
if ($lastid == " ")
{
$empid ="RFC-0001";
}
else
{
$empid = substr($lastid, 4);
$empid= intval($empid);
$empid= "RFC-".($empid +1);
}
?>
<html>
<body>
<form method="post" action="">
<input type="text" name="ID" value="<?php echo $empid; ?>"readonly>
</br>
<input type="text" name="name">
</br>
<input type="button" name="done" value="done">
</form>
</body>
</html>