简体   繁体   中英

php - Change Button on Form Submit

I am working on a project that takes student(s) attendance. The process of this application is basically student logs in with their student id, and they will be logged in and can view the attendance sheet. All they have to do is click time in and it will log their data into the database. The time out post is just optional for practice for bigger projects in the near future.

What I am trying to figure out, is how can I change the button when the form submits. I want to be able to display a time out button when form is submitted. I am trying to avoid as much AJAX as possible, because I am not yet in that line of work.

This is the code that I am working with:

<?php

require_once './dba.php';

$status = "";

if(isset($_POST['time_in'])) {

    $dt = $_POST['dt'];
    $time = $_POST['time'];

    $query = "INSERT INTO punchtest (date, time) VALUES ('$dt', '$time')";

    $d = $conn->prepare($query);

    $d->execute();     

    header("location: ./homepage.php");

    $newButton = "<button class='btn btn-primary' for='testEr' name='time_out'>Time Out</button>";

} elseif(isset($_POST['time_out'])) {
    $query = "UPDATE punchtest SET datetime = NOW() WHERE id = 1";

    $d = $conn->prepare($query);

    $d->execute();    

    $newButton = "<button class='btn btn-primary' for='testEr' name='time_in'>Time In</button>";

} else {
    $newButton = "<button class='btn btn-primary' for='testEr' name='time_in'>Time In</button>";
}


?>

<html>
<?php echo $newButton; ?> 
</html>

How am I able to fix this issue? Thank you

The following line needs to be removed.

header("location: ./homepage.php");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM