Save independently for each DATE

0

Greetings,

I am doing a medical consultation program and I need to do the following but I can not find a way to do it:

I need that every time a patient comes to my medical consultation, I keep with the day the medical history came, so that the next time he comes back I can see the previous stories according to his date.

Currently I only have the following, but I do not know how to do a query by date and then check that date to see what was written that day.

As I have it, I can only modify the file already created, but I do not know how to stop separating by dates, I attach photos from my database

<?php  

include('conexion.php');
$boton = $_POST["boton"];
$cedula = $_POST["CED_PAC"];
$nombre = $_POST["NOM_PAC"];
$apellido = $_POST["APE_PAC"];
$edad = $_POST["EDAD_PAC"];
$nhistoria = $_POST["HIS_PAC"];
$direccion = $_POST["DIR_PAC"];
$telefono = $_POST["TEL_PAC"];
$celular = $_POST["CEL_PAC"];
$sexo = $_POST["SEX_PAC"];
$codigo = $_POST["COD_CONSULTA"];
$fecha = $_POST["FECHA"];
$tipconsulta = $_POST["TIPO_CONSULTA"];
$observacion = $_POST["OBSERV"];
$sintomas = $_POST["SINTOMAS"];
$peso = $_POST["PESO_PAC"];
$altura = $_POST["ALT_PAC"];
$operado = $_POST["OPERADO"];
$alergias = $_POST["ALERGIAS"];
$medicamentos = $_POST["MEDI_PAC"];

if ($boton == "Registrar"){
	$sql = "insert into datosmedicos (CED_PAC, ALT_PAC, PESO_PAC, COD_CONSULTA, TIPO_CONSULTA, SINTOMAS, OBSERV, OPERADO, ALERGIAS,MEDI_PAC ) values ('$cedula','$altura', '$peso', '$codigo', '$tipconsulta', '$sintomas', '$observacion', '$operado', '$alergias', '$medicamentos')";

	if (mysql_query($sql)){
		echo "<script>alert('Usuario guardado correctamente')</script>";
		echo "<script> window.location='consulta.php'</script>";
	}
	else{
		echo "<script>alert('El usuario no puede ser registrado, compruebe que todos los campos esten llenos')</script>";
	}
}

if ($boton == "Buscar"){
	$sql = "select * from datosbasicos where CED_PAC = '$cedula'";
	$busqueda =mysql_query($sql);

	if ($registro=mysql_fetch_array($busqueda)){
		$cedula = $registro['CED_PAC'];
		$nhistoria = $registro['HIS_PAC'];
		$sexo = $registro['SEX_PAC'];
		$nombre = $registro ['NOM_PAC'];
		$apellido = $registro ['APE_PAC'];
		$edad = $registro['EDAD_PAC'];
		$direccion = $registro['DIR_PAC'];
		$telefono = $registro['TEL_PAC'];
		$celular = $registro['CEL_PAC'];
	}

else{
	echo "<script>alert('Paciente no encontrado en el sistema')</script>";
	}
}
if ($boton == "Buscar"){
	$sql1 = "select * from datosmedicos where CED_PAC = '$cedula'";
	$busqueda1 =mysql_query($sql1);

	if ($registro1=mysql_fetch_array($busqueda1)){
		$codigo = $registro1['COD_CONSULTA'];
		$altura = $registro1['ALT_PAC'];
		$peso = $registro1['PESO_PAC'];
		$fecha = $registro1['FECHA'];
		$tipconsulta = $registro1['TIPO_CONSULTA'];
		$sintomas = $registro1['SINTOMAS'];
		$observacion = $registro1['OBSERV'];
		$nhistoria = $registro1['HIS_PAC'];
		$cedula = $registro1['CED_PAC'];
		$medicamentos = $registro1['MEDI_PAC'];
		$operado = $registro1['OPERADO'];
		$alergias = $registro1['ALERGIAS'];

	}
}

if ($boton == "Modificar"){
	if ($cedula!=""){
	$sql="UPDATE datosmedicos SET ALT_PAC= '$altura', PESO_PAC='$peso', FECHA='$fecha', TIPO_CONSULTA='$tipconsulta', SINTOMAS='$sintomas', OBSERV='$observacion', HIS_PAC=$nhistoria, MEDI_PAC='$medicamentos', OPERADO='$operado', ALERGIAS='$alergias' where CED_PAC='$cedula'";
		mysql_query($sql);
		echo "<script>alert('Datos modificados correctamente')</script>";
		echo "<script>window.location='consulta.php'</script>";
	}
	else{
		echo "<script>alert('Para poder modificadar debe realizar una busqueda')</script>";
		echo "<script>window.location='consulta.php'</script>";
	}
}
?>

<!DOCTYPE html>
<html>
<head>
	<title>Sistema de historias médicas - Dr. Darling Davila</title>
	<meta charset="utf-8">
	<link rel="stylesheet" href="css/bootstrap.css">
	<link rel="stylesheet" type="text/css" href="css/estilo.css">
	<link href="https://fonts.googleapis.com/css?family=Lato|Roboto" rel="stylesheet">
</head>
<body>
<form action="" method="post">
<img src="imagenes/header.png">
	<h2>Historia médica</h2>
	<div class="contenedor">
		<input type="text" placeholder="Cedula" name="CED_PAC"  value="<?PHP echo $cedula; ?>">
		<input type="text" placeholder="Número de historia" name="HIS_PAC"  value="<?PHP echo $nhistoria; ?>">
		<input type="text" placeholder="Nombre del paciente" name="NOM_PAC"  value="<?PHP echo $nombre; ?>">
		<input type="text" placeholder="Apellido del paciente" name="APE_PAC"  value="<?PHP echo $apellido; ?>">
		<input type="text" placeholder="Edad" name="EDAD_PAC"  value="<?PHP echo $edad; ?>">
		<input type="text" placeholder="Peso" name="PESO_PAC"  value="<?PHP echo $peso; ?>">
		<input type="text" placeholder="Altura" name="ALT_PAC"  value="<?PHP echo $altura; ?>">
		<input type="date" placeholder="Fecha" name="FECHA"  value="<?PHP echo $fecha; ?>">
		<input type="text" placeholder="Codigo de consulta" name="COD_CONSULTA" class="input-100"  value="<?PHP echo $codigo; ?>">
		<input type="text" placeholder="Tipo de consulta" name="TIPO_CONSULTA" class="text-center input-48" value="<?PHP echo $tipconsulta; ?>">
		<textarea name="SINTOMAS" class="input-100" placeholder="Sintomas" rows="10" cols="40"><?php echo $sintomas; ?></textarea>
		<textarea name="OBSERV" class="input-100" placeholder="Observaciones" rows="10" cols="40"><?php echo $observacion; ?></textarea>
	 	<textarea name="OPERADO" class="input-100" placeholder="Ha sido operado" rows="10" cols="40"><?php echo $operado; ?></textarea>
		<textarea name="ALERGIAS" class="input-100" placeholder="Sufre de alergias" rows="10" cols="40"><?php echo $alergias; ?></textarea>
		<textarea name="MEDI_PAC" class="input-100" placeholder="Medicamentos actuales" rows="10" cols="40"><?php echo $medicamentos; ?></textarea>

			<input type="submit" name="boton" value="Registrar" class="text-center inline-block col-md-3 btn-enviar espacio-arriba">
			<input type="submit" name="boton" value="Buscar" class="text-center inline-block col-md-3 btn-enviar espacio-arriba">
			<input type="submit" name="boton" value="Modificar" class="text-center inline-block col-md-3 btn-enviar espacio-arriba">
			<input type="button" value="Atras" class="text-center inline-block col-md-3 espacio-arriba btn-enviar" onclick = "location='menu.php'"/>


	</div>
	</form>


</body>
</html>
    
asked by Pablo Pernia 19.08.2017 в 17:48
source

1 answer

0

You should first change the data type to your DATE field by DATETIME , then to consult dates you would do something like this: WHERE FECHA >= '2017-01-22 15:31:00' If you want, you can also add a field FECHAULTIMA or similar, with the data type DATETIME and DEFAULT CURRENT_TIMESTAMP , field that would always be updated in each modification of the record.

Example:

'FECHA' DATETIME NULL DEFAULT NULL,
'FECHAULTIMA' DATETIME NULL DEFAULT CURRENT_TIMESTAMP,

This way you can access the date of last modification and DATE could be used for another reference you need like when the record was created, or simply use the latter.

Please do not forget to escape your data to prevent SQL injection with mysqli_real_escape_string (or sentences prepared ) and using mysqli instead of mysql that is obsolete.

Greetings

    
answered by 19.08.2017 в 18:22