PHP Show the time you clicked the button and by whom it was clicked

Asked

Viewed 145 times

1

Next, I’m creating a page of employees that will work in the "punch card" scheme. That is, whenever the employee arrives, he will click the button inside the system and the intention was to show the time that was clicked and stay there. Then, when he left, he would "hit card" again and show the time. At the end of the day, this would be "zeroed" (i.e., the button appeared again) and the time, date and these things would go into the employee’s history. However, I don’t have much idea how to do this, since my knowledge of programming is not so advanced.

I do not know how to make appear the cute date in the table next. I tried to make an if, includes an isset. Anyway, I tried several methods but I have no idea how to do it. I’m open to suggestions, opinions. I really need to do this!

Thank you!

<?php

include './abreConexao.php';

$sqlFunc = "Select * from FUNCIONARIOS";
$rsFunc = mysql_query($sqlFunc) or die (mysql_error());

?>

<table border="1">
    <?php
while($tblFunc = mysql_fetch_array($rsFunc)){

?>

    <tr>

        <td>

            <?=$tblFunc['nome_FUNCIONARIO']?> 

        </td>



        <td align="center">


            <form action="Funcionarios.php" method="POST">
            <input type="submit" value="" name="horaEntrada">
            </form>

        </td>

        <td align="center">

            <input type="submit" value="" name="horaSaida">

        </td>

    </tr>

<?php 


    } ?>


    </table>

WHAT I TRIED TO DO WAS:

    <?php 

    $horaEntrada = $_POST['horaEntrada'];


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

    $horaEntrada = 1;

}else{

    $horaEntrada = 0;

}

if($horaEntrada == 1){

    date_default_timezone_set('America/Sao_Paulo');
$date = date('Y-m-d H:i');
echo $date;

}
  • You can’t understand where the difficulty is. Can you explain it better, please? Do you already have a database? A feature like this requires a database.

  • Yes, I have the database, the employee table included.

  • My main difficulty is: how do I do this scheme of "hit card". If it does not click, there will be the option. When the particular employee clicks (i.e., on his "part") make appear the cute date. I even managed to get the date out, but I don’t know how to get this idea to stick to the employee who clicked and then automatically reset and go to the history. I don’t know if you understand...

  • I think you better show the relevant snippets of the code. Maybe it’s material for more than one question.

  • Vish, there’s so much... I only send what’s on the staff page?

  • Just put the snippet where you think the problem is. If possible by cutting unnecessary parts

  • Well, I put what I had tried to do (kind of silly, but that’s what came into my head to solve) and also put the page that I’m doing, but I cut some parts that I thought were unnecessary. My first question is: Do I php on the employee page itself or create another one? If I create another, how to retouch to the employees page with the changed information?

Show 2 more comments

1 answer

0

Pretty quiet, assuming you know the code, which is simple, I’ll just give you the logic.

1- Make a small form, where the employee enters with the registration ($license plate) and gives Submit through the button. 2- On another page you receive $registration by POST and keep it in the bank as well as the exact moment the bank updated.

Small example of processing:

<?php
include("db.php");
$matricula    = $_POST['matricula'];
$fuso         = mktime(date("H")-3, date("i"), 0);
$hora_ponto   = gmdate("Y-m-d H:i", $fuso);

$ponto = $conexao->exec("INSERT INTO `funcionarios` ( `matricula` , `hora_ponto`) VALUES ('$matricula', '$hora_ponto')");
$ultimaid = $conexao->lastInsertId();
echo '<center>Registro: '.$hora_ponto;}
header("location: suapagina.php");
?>

At the end of the month you can easily print out a report of all records entered by license x.

I believe that with this you can make any Tweak necessary to adapt to your need.

  • Sorry, that license plate you refer to would be when he clicked on the "button"?

  • This, makes an input with name="matricula" and the Submit on the button, will require the user to enter the registration in this field.

  • Could you elaborate on that? I’m really sorry and I really appreciate your help!

  • You need a form like this: https://jsfiddle.net/0wbtbzep/ The user enters his registration and click on Register, on the page processing.php you have the code I passed earlier.

  • 1

    Ah, I think I get it. On this plate he writes something and then he’ll be redirected to the page that does it, right? And how would I go back to the previous page showing the employee date and time?

  • I edited the answer with the redirect to another page at the end of the processing, just you edit to your liking, now the return of information as the date and time that was performed the record is another case, search on this.

  • Ah, I get it. Thank you so much!

  • Should I create a table facing these times? A table focused exclusively on this history that will form?/

  • 1

    It is ideal, since you will be inserting a new line at each point record. The "employees" table would then store the employee’s personal information such as contacts and address, and the "point" point records performed by the employee. One thing that is ideal to remind you is that with this system the user enter his registration, anyone can register point for anyone else.

  • Yes, I thought of that hypothesis. Maybe if I entered a type of password or code?

  • It does not help much, a session system (login and password) would not prevent the employee to pass the password to another, but finally...

  • Oh yes, I understand. Anyway, the date and time is still the crucial problem I still have...

Show 7 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.