0 votes

How to save form data and avoid duplicates?

I'm making a website to manage a care agenda, I know a little bit of js but not enough.... I know that I will have to resort to ajax, mysql, php or any of these. My intention is to save the date with: the month, day, and hours, in a database. and at the same time send them to my email and then link them to google calendar The purpose of doing this is to avoid duplicate dates and times.... The form is something simple based on boostrap, there are some traces of a un js to avoid that the input time is after the output time.

A problem arises with the hours because if I choose for example from 13:00 to 17:00 when saving it is important that the 14 15 and 16 hrs also include this selection.

Any guidance I can turn to? More than anything I need the path I have to follow, I searched for the topics separately but then I don't know how to put them together. Thanks in advance!

~

<form action="prog.php" method="post" name="formulario" id="formu" onsubmit="return comprobar()">
  <div class="form-row">
  <div class="form-group col-md-1s">
       <label for="inputState">Mes</label>
      <select id="inputState" name="mes" class="form-control">

        <option>enero</option>
        <option>febrero</option>
        <option>marzo</option>
        <option>abril</option>
        <option>mayo</option>
      </select>
    </div>
   <div class="form-group col-md-1">
      <label for="inputState">Dia</label>
      <select id="inputState" name="dia" value="" class="form-control">

       <option>1</option>
        <option>2</option>
        <option>3</option>
        <option>4</option>
        <option>5</option>
      </select>
      </div>    
  <div class="form-group col-md-2">
      <label for="inputState">Entrada</label>
      <select id="inputState" name="entrada" class="form-control" value="">
        <option>12:00</option>
        <option>13:00</option>
        <option>14:00</option>
        <option>15:00</option>
      </select>
      </div>
      <div class="form-group col-md-2">
      <label for="inputState"> Salida</label>
      <select id="inputState" name="salida" class="form-control" value=""> 
        <option>13:00</option>
        <option>14:00</option>
        <option>15:00</option>
        <option>16:00</option>
        <option>17:00</option>
      </select>
      </div>
</div>

~

0voto

JCLXS Points 31

In MySQL create your table, and when you create the date_record field you choose the type of data it will receive, in this case it is of type "DATETIME" which can handle everything related to date, hour, minutes and seconds. Then in your form you only have to collect the parts that will compose your date, if you want to set it as you want, otherwise it could be the date of the day automatically with the PHP "Date" function... date('l jS \of F Y h:i:s A'); you can put it in an input of your form. Then for filtering you can make a comparison with a defined range something like...

$myfechaForm = $_POST['fechadelform'];
$fechaINI = "2019-07-25:13:00:00";  <-- Puedes usar la "date de php" para crear la fecha
$fechaFIN = "2019-07-25:17:00:00";

if($myfechaForm >= $fechaINI && $myfechaForm <= $fechaFIN){

AQUƍ EJECUTAS LA SENTENCIA SQL PARA INSERTAR LOS DATOS A TU TABLA CON LA FECHA CORRECTA

} else {

  echo "REGISTRO FUERA DEL HORARIO";
}

HolaDevs.com

HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by:

X