I want to auto generate the id number. I write this code. But it's not work. I don't make primary key for id in database.
function getData()
{
$data = array();
$data[1] = $_POST['name'];
$data[2] = $_POST['fname'];
$data[3] = $_POST['address'];
$data[4] = $_POST['phone'];
$data[5] = $_POST['class'];
$data[6] = $_POST['qualification'];
$data[7] = $_POST['branch'];
$data[8] = $_POST['rollno'];
$data[9] = $_POST['gender'];
$data[10] = $_POST['birth'];
return $data;
}
//insert
if (isset($_POST['insert'])) {
$info = getData();
$insert_query = "INSERT INTO `smash`(`name`, `fname`, `address`, `phone`,`class`,`qualification`,`branch`,`rollno`,`gender`,`birth`) VALUES ('$info[1]','$info[2]','$info[3]','$info[4]','$info[5]','$info[6]','$info[7]','$info[8]','$info[9]','$info[10]')";
try {
$insert_result = mysqli_query($conn, $insert_query);
if ($insert_result) {
if (mysqli_affected_rows($conn) > 0) {
echo ("data inserted successfully");
} else {
echo ("data are not inserted");
}
}
} catch (Exception $ex) {
echo ("error inserted" . $ex->getMessage());
}
}