Ideas of how to validate scheduled dates and times by means of only input

0

To explain myself better I'm doing a school project together (as a team), the project is a dating management system in the dental office field. In which I am currently stuck since I do not know how to proceed to validate appointments, for example, add a date and time of the appointment and if it is already registered, that sends a message of "This date is already scheduled, enter another please ", it will be very helpful if you give me advice or tips since it is my first time doing this, we are currently using Php and Mysql, I would be very grateful.

If you do not explain well, please comment. Thanks.

    
asked by Cesar Reyna 13.08.2018 в 00:43
source

2 answers

0

You can make a selection and only make a query with the date that you gave in the example form:

$fecha = "23 Sep 2018"; //ejemplo
$resultado = mysqli_query($conexion, "SELECT * FROM citas WHERE fecha='".$fecha."'";
if(mysqli_num_rows($resultado) > 1){
  echo "la fecha ya esta en la agenda";
}else{
  //tu codigo
}
    
answered by 13.08.2018 в 00:58
0

I recommend you use the datetimepicker plugin I leave you in link to review the documentation: datetimepicker

This plugin will allow you to capture the date and time of the appointment more easily.

Another recommendation is when creating the table, as a good practice you have to add a unique index for the date of the appointment, since this should not be repeated, I leave an example in MySQL of the create:

CREATE TABLE 'cita' (
    'id' INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    'name' VARCHAR(255) NOT NULL COLLATE 'utf8_unicode_ci',
    'user_name' VARCHAR(255) NOT NULL COLLATE 'utf8_unicode_ci',
    'fecha' TIMESTAMP NULL DEFAULT NULL,
    PRIMARY KEY ('id'),
    UNIQUE INDEX 'fecha' ('fecha')
)

In this line the unique index is added:

UNIQUE INDEX 'fecha' ('fecha')
    
answered by 13.08.2018 в 01:06