Hello everyone.
I have the following problem
get the last id from the database
but you can not insert a text field, the last id
has, solution?
pls pls
<?
$localhost = "localhost";
$username = "username";
$password = "password";
$dbname = "nameMyDB";
$conn = mysqli_connect($localhost, $username, $password, $dbname);
// Check connection
if (!$conn) { die("Connection failed: " . mysqli_connect_error()); }
$sql = "INSERT INTO Guests (firstname, lastname, code) VALUES ('Sam', 'Smith', '1')";
if (mysqli_query($conn, $sql)) {
$last_id = mysqli_insert_id($conn);
echo "created successfully. Code is: COD" . $last_id;
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
?>
<form action="Test.php" method="post">
<input name="firstname" type="text">
<input name="lastname" type="text">
<input name="code" type="text" value="COD<? echo $last_id;?>">
<input name="Send" type="submit">
</form>
Result;
Names: Sam Smith
Code: COD1
Names: Tim Thompsom
Code: COD2
etc..