isset函数不起作用

below i inserted my two forms

<html>
<body>
<center>
<h2>working time</h2>
<form action="" method="post">
<button name="starttime" class="starttime">starttime</button>
<?php
session_start();
$name = $_SESSION["name"];
echo $name;
if(isset($_POST["starttime"])){
$date = date('Y-m-d');
require "database.php";
$sql = "SELECT name, ddate FROM karthick.date WHERE name = '$name' AND ddate = '$date'";
$result = $conn->query($sql);
if($result->num_rows > 0){
    while($row = $result->fetch_assoc()){
        $n = $row["name"];
        $d = $row["ddate"];
    }
}
if($n == $name && $d == $date){
    echo'<script>
    alert("Time already registered");
    </script>';
}else{
    header("location:http://localhost/karthick/attendance/datedata.php");
    exit;
}
}
?>
</form>
<form action = "datedata.php" method="post">
<button name="endtime" class="endtime">Endtime</button>
</form>
<form action="user.php" method="post">
<button name= "logout" class="logout">Logout</button>
</form>
</body>
</html>

in the above form when the starttime is clicked it fetch the date and it check it with database if the date is already registered or not.if the date is not already registered it moves to next formthat i gave it in the header:link.

secode form

<?php
require 'database.php';
session_start();
$name = $_SESSION["name"];
echo $name;
if(isset($_POST["starttime"]))
{
    $date_clicked = date('H:i:s');
    echo $date_clicked;
    $date_clicked1 = date('Y-m-d');
    echo $date_clicked1;
    $sql = "INSERT INTO karthick.date (name, ddate, starttime) VALUES ('$name', '$date_clicked1', '$date_clicked')";
    if($conn->query($sql) === TRUE){
        echo "inserted";
    }else{
        echo "error";
    }
}elseif(isset($_POST['endtime']))
{
    $date_clicked = date('H:i:s');
    $date_clicked1 = date('Y-m-d');
    $sql = "UPDATE karthick.date SET endtime='$date_clicked' WHERE name = '$name' AND ddate = '$date_clicked1'";
    if($conn->query($sql) === TRUE){
        echo "inserted";
    }else{
        echo "error";
        echo $name;
    }
}
$conn->close();
?>

so the problem i am facing is when it moves to second form it only fetch the name and it doesn't fetch the date and time. so please help me.

Your button has no value assigned, this will skip it on $_POST request:

<button name="starttime" class="starttime" value="insert value here">starttime</button>

Also you are missing the destination of your form action="" (it will default to the origin page, but it's better to declare it).

Then, when you change to the second form via the header statement

 header("location:http://localhost/karthick/attendance/datedata.php");

It's not a $_POST request anymore, you would have load this via ajax and add post values, or pass them otherwise. The $_SESSION variables stay anyway, of course.