I have edited this post to see if I can understand I'm trying to make an insert so that only allows 3 records to enter per date, I mean 2017-02-12, to this date there can only be three records, for a new record you should try another day or better with another date, If there are already three records with the same date and it is about making another record with the same date already registered, you should send a message: ('The limit of daily records has been exceeded, try another date!') I currently have this, but the error it gives me is that it only sends the message that ('The limit of daily records has been exceeded, try another date. ! ') and does not register
<?php
include("conexion.php");
if (isset ($_POST['guardar'])){
$cedula=$_REQUEST['cedula'];
$idtipodecita=$_REQUEST['idtipodecita'];
$fecha_cita=$_REQUEST['fecha_cita'];
$estado=$_REQUEST['estado'];
$telefono=$_REQUEST['telefono'];
$cita_x_dia = 2;
$sql="SELECT COUNT(*) FROM cita_previa WHERE fecha_cita='$fecha_cita'";
$res=mysql_query($sql,$link) or die ( mysql_error());
$nrows=mysql_num_rows($res);
if($res <= $cita_x_dia)
{
if (mysql_query("INSERT INTO cita_previa (cedula,idtipodecita,fecha_cita,estado,telefono) VALUES
('$cedula','$idtipodecita','$fecha_cita','$estado','$telefono')",$link)){
echo "<script>alert ('Cita Previa registrada, pronto lo contactaremos!');</script>
<META HTTP-EQUIV='REFRESH' CONTENT=0;URL=http:citaprevia.php>";
}else{
echo "<script>alert ('Se ha superado el limite de registros diarios, intente con otra Fecha!');</script>
<META HTTP-EQUIV='REFRESH' CONTENT=0;URL=http:citaprevia.php>";
}
?>
I have finally solved it and in this way I am adding the cod for those who can use it thanks to a friend ... with this I give the subject as closed
<?php
include("conexion.php");
if (isset ($_POST['guardar'])){
$cedula=$_REQUEST['cedula'];
$idtipodecita=$_REQUEST['idtipodecita'];
$fecha_cita=$_REQUEST['fecha_cita'];
$estado=$_REQUEST['estado'];
$telefono=$_REQUEST['telefono'];
$sql="SELECT COUNT(*) AS 'Registros' FROM cita_previa WHERE fecha_cita='$fecha_cita'";
$res=mysql_query($sql,$link) or die ( mysql_error());
$nrows=mysql_num_rows($res);
list( $no_registros ) = mysql_fetch_array($res);
if( $no_registros >= 2 ) {
echo "<script>alert ('Se ha superado el limite de registros diarios, intente con otra Fecha!');</script><META HTTP-EQUIV='REFRESH' CONTENT=0;URL=http:citaprevia.php>";
die (' ');
}else{
mysql_query("INSERT INTO cita_previa (cedula,idtipodecita,fecha_cita,estado,telefono) VALUES('$cedula','$idtipodecita','$fecha_cita','$estado','$telefono')",$link);
echo "<script>alert ('Cita Previa registrada, pronto lo contactaremos!');</script><META HTTP-EQUIV='REFRESH' CONTENT=0;URL=http:citaprevia.php>";
}
?>