PHP - Registro de formulario de Citas en Mysql-phpmyAdmin

 
Vista:
Imágen de perfil de jeinz
Val: 7
Ha aumentado su posición en 20 puestos en PHP (en relación al último mes)
Gráfica de PHP

Registro de formulario de Citas en Mysql-phpmyAdmin

Publicado por jeinz (20 intervenciones) el 24/04/2015 21:26:14
Buen dia Ingenieros La Web del Programador.

Mi problema es el siguiente: tengo una base datos MySql para reserva de citas. Pero cuando le doy grabar cita este solo registra la hora y el asunto, no registra la fecha en curso, ni la nueva fecha de la cita y tambien sobre escribe sobre los mismos registros he revisado una y otra vez y no encuentro el error. No he podido solucionar.

El codigo es el siguiente:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<!Doctype html>
<html lang="es">
<head>
<title>Agregar nueva cita</title>
<script language="javascript" type="text/javascript">
   function mandar(resultado){
     if (resultado){
       document.formularioNuevaCita.action="grabarNuevaCita.php";
     }else {
       document.formularioNuevaCita.action="aplicativo.php";
     }
     document.formularioNuevaCita.submit();
   }
</script>
</head>
<body>
	<?php
// se incluye el script de tratamiento de fechas
	include("fechas.php");
// se muestra la fecha en curso
	echo ("CITA PARA EL DIA: ".$diaActual." del ".$mesActual. " de ".$annioActual.salto);
	?>
	<form action="" method="POST" name="formularioNuevaCita" id="formularioNuevaCita">
		<input type="hidden" name="fechaEnCurso" id="fechaEncurso" value="<?php echo($fechaEncurso);?>">
		<table width="500" border="0" cellspacing="0" cellpadding="2">
		<tr>
			<td>
 
			</td>
		</tr>
			<tr>
				<td width="73">Hora:</td>
				<td width="427">Cita:</td>
			</tr>
			<tr>
				<td><select name="hora" id="hora">
					<?php
					for ($i=0;$i<24;$i++){
						echo ("<OPTION VALUE='");
						printf("%02s",$i);
						echo("'>");
						printf("%02s", $i);
						echo("</OPTION>".salto);
					}
					?>
				</select></td>
				<td rowspan="3"><textarea name="asunto" cols="50" rows="5" id="asunto"></textarea></td>
			</tr>
			<tr>
				<td>Minutos:</td>
			</tr>
			<tr>
				<td><select name="minutos" id="minutos">
					<?php
					for ($i=0; $i<51; $i+=10) {
						echo ("<OPTION VALUE='");
						printf("%02s", $i);
						echo ("'>");
						printf("%02s", $i);
						echo ("</OPTION>".salto);
					}
					?>
				</select></td>
			</tr>
		</table>
		<table width="500" height="44" border="0" cellspacing="0" cellpadding="0">
			<tr align="center">
				<td width="248"><input name="grabarCita" type="button" id="grabarCita" value="Grabar la Cita" onclick="javascript:mandar(true);"></td>
				<td width="252"><input name="anularCita" type="button" id="anularCita" value="Cancelar" onclick="javascript:mandar(false);"></td>
			</tr>
		</table>
	</form>
</body>
</html>

Este el codigo de grabarNuevaCita:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<!DOCTYPE HTML>
<html lang="es">
  <head>
  <script language="javascript" type="text/javascript">
    function volver(){
      document.retorno.submit();
    }
  </script>
  </head>
  <body onLoad="javascript:volver();">
  <?php
// Se incluye el miniscript de tratamiento de fechas
  include ("fechas.php");
// Se incluye el miniscript que abre la base de datos.
  include ("conectar_bd.php");
// Se crea la hora, a partir de las horas y minutos establecidos en el formulario de nueva cita.
  $horaDeCita=$_POST["hora"].":".$_POST["minutos"];
// Se monta la consulta para grabar una nueva cita.
  $consulta="INSERT INTO citas (diaCita, horacita, asuntocita) VALUES ('$fechaEnCurso','$horaDeCita','".$_POST["asunto"]."');";
// Se ejecuta la consulta.
  $hacerConsulta=mysql_query ($consulta,$conexion);
// Se liberan recursos y se cierra la base de datos.
  @mysql_free_result($hacerConsulta);
  mysql_close($conexion);
  ?>
  <form action="aplicativo.php" name="retorno" id="retorno" method="post">
    <input type="hidden" name="fechaEnCurso" id="fechaEnCurso" value="<?php echo ($fechaEnCurso); ?>">
  </form>
  </body>
</html>


Este es codigo de cambiar fechas:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<html>
  <head>
    <?php
// Se incluye el miniscript de manejo de fechas.
      include ("fechas.php");
    ?>
    <title>Cambio de fecha</title>
    <script language="javascript" type="text/javascript">
/* La siguiente función se activa cuando se pulsa el botón de aceptar una nueva fecha o el de
descartar cambios para seguir con la fecha actual. Si se pulsa el de aceptar una nueva fecha,
el argumento vale true y se cambia el campo oculto de fecha al valor seleccionado por el usuario.
En caso de que el argumento valga false (si se ha pulsado en el botón de descarte), no se producen
cambios en el campo oculto, con lo que tiene el contenido por defecto.*/
      function enviar(cambio){
        if (cambio){
          document.getElementById("fechaEnCurso").value=document.getElementById("annio").value+"-"+document.getElementById("mes").value+"-"+document.getElementById("dia").value;
        }
        document.formularioDeCambioDeFecha.submit();
      }
/* La siguiente función establece, en las listas, los valores de la fecha actual como seleccionados.*/
      function ajustarCampos(){
        document.getElementById("dia").value="<?php echo ($diaActual); ?>";
        document.getElementById("mes").value="<?php echo ($mesActual); ?>";
        document.getElementById("annio").value="<?php echo ($annioActual); ?>";
      }
    </script>
  </head>
<body onLoad="javascript:ajustarCampos();">
  <form action="aplicativo.php" method="post" name="formularioDeCambioDeFecha" id="formularioDeCambioDeFecha">
    <input type="hidden" name="fechaEnCurso" id="fechaEnCurso" value="<?php echo ($_POST["fechaEnCurso"]); ?>">
  </form>
  <p>LA FECHA ACTUAL ES:&nbsp;
  <?php
/* Se muestra la fecha en curso.*/
    echo ($diaActual." del ".$mesActual." de ".$annioActual);
  ?>
  </p>
  <p>SELECCIONE LA NUEVA FECHA:</p>
  <table width="500" border="0" cellspacing="0" cellpadding="2">
    <tr>
      <td width="40" align="right">DIA:</td>
      <td width="100"><select name="dia" id="dia">
        <?php
          for ($i=1;$i<=31;$i++){
            echo ("<OPTION VALUE='");
            printf ("%02s",$i);
            echo ("'>");
            printf("%02s",$i);
            echo ("</OPTION>".salto);
          }
        ?>
      </select></td>
      <td width="60" align="right">MES:</td>
      <td width="161"><select name="mes" id="mes">
        <option value="01">Enero</option>
        <option value="02">Febrero</option>
        <option value="03">Marzo</option>
        <option value="04">Abril</option>
        <option value="05">Mayo</option>
        <option value="06">Junio</option>
        <option value="07">Julio</option>
        <option value="08">Agosto</option>
        <option value="09">Septiembre</option>
        <option value="10">Octubre</option>
        <option value="11">Noviembre</option>
        <option value="12">Diciembre</option>
      </select></td>
      <td width="69" align="right">A&Ntilde;O:</td>
      <td width="70"><select name="annio" id="annio">
        <?php
          for ($i=2006;$i<=2020;$i++) echo ("<OPTION VALUE='".$i."'>".$i."</OPTION>".salto);
        ?>
      </select></td>
    </tr>
  </table>
  <p>
    <input name="aceptarCambio" type="button" id="aceptarCambio" value="Aceptar Cambio" onClick="javascript:enviar(true);">
    <input name="descartarCambio" type="button" id="descartarCambio" value="Descartar Cambio" onClick="javascript:enviar(false);">
</p>
</body>
</html>

y este es el codigo de fechas:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
// Se define una secuencia para el salto de línea.
  define ("salto","\n<br>\n");
/* Se determina si existe una variable de formulario (POST) con la fecha en curso de la agenda.
Si existe, la variable de memoria de la fecha se ajusta al contenido de la del formulario
(proceda de donde proceda). Si no existe, se toma la fecha del sistema.*/
  if (isset($_POST["fechaEnCurso"])){
      $fechaEnCurso=$_POST["fechaEnCurso"];
  } else {
      $fechaEnCurso=date("Y-m-d");
  }
/* A partir de la variable de memoria con la fecha en curso, se obtiene el año, el mes y el dia. */
  $annioActual=substr($fechaEnCurso,0,4);
  $mesActual=substr($fechaEnCurso,5,2);
  $diaActual=substr($fechaEnCurso,8);
?>

Gracias por su colaboracion. Adjunto envio la imagen de como quedan los registros.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
1
Responder