简体   繁体   English

php - 提交表单时的更改按钮

[英]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.我尽量避免使用 AJAX,因为我还没有从事那项工作。

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");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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