I just started to learn php and in this code i want to auto generate an id number and call it
Here is my code for creating table:
<?php
$link = mysqli_connect("localhost","root","","demo");
$sql="CREATE TABLE persons(first_name VARCHAR(30) NOT NULL, id INT (1) NOT NULL PRIMARY KEY
AUTO_INCREMENT)";
if(mysqli_query($link,$sql))
{ echo "Table created successfully.";}
mysqli_close($link);
?>
Code for adding values and i want to call the value of my id number and display it here but i dont know how.
<!DOCTYPE html>
<html>
<body>
<form action="insert.php" method="post">
First name: <input type="text" name="first_name">
ID no: <name="id">
<input type="submit" value="Submit Form">
</body>
</html>
Code for inserting the values:
<html>
<?php
$link = mysqli_connect("localhost", "root", "", "demo");
$first_name = mysqli_real_escape_string($link, $_REQUEST['first_name']);
$id = mysqli_real_escape_string($link, $_REQUEST['id']);
$sql = "INSERT INTO persons (first_name,id)
VALUES('$first_name','$id')";
mysqli_close($link); ?>
</html>