PHP - problema al guardar en la BBDD

 
Vista:
Imágen de perfil de siREZ
Val: 23
Ha disminuido su posición en 95 puestos en PHP (en relación al último mes)
Gráfica de PHP

problema al guardar en la BBDD

Publicado por siREZ (203 intervenciones) el 05/12/2013 07:02:49
Cordial saludo.

el siguiente scriip inserta en la tabla tcalendario, los datos leidos en el formulario.
imprime: Evento guardado correctamente
guarda en la tabla los campos: codigo fecha, evento pero no guarda paciente

no veo el error.

en: require_once("seleccionar paciente.php"); hace la correcta selección

gracias.

siREZ


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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<?php session_start();$codigo = $_SESSION['codigo'];$nombre = $_SESSION['nombre_usuario'];
error_reporting(-1);
require_once("config.inc.php");
require_once("seleccionar paciente.php");
function fecha ($valor)
{
	$timer = explode(" ",$valor);
	$fecha = explode("-",$timer[0]);
	$fechex = $fecha[2]."/".$fecha[1]."/".$fecha[0];
	return $fechex;
}
 
function buscar_en_array($fecha,$array)
{
	$total_eventos=count($array);
	for($e=0;$e<$total_eventos;$e++)
	{
		if ($array[$e]["fecha"]==$fecha) return true;
	}
}
 
switch ($_GET["accion"])
{
	case "guardar_evento":
	{
		$query="insert into tcalendario (paciente,codigo,fecha,evento) values ('".strip_tags($_GET["paciente"])."','$codigo','".$_GET["fecha"]."','".strip_tags($_GET["evento"])."')";
		mysql_select_db($dbname);
		if ($resultado=mysql_query($query)) echo "<p class='ok'>Evento guardado correctamente.</p>";
		else echo "<p class='error'>Se ha producido un error guardando el evento.</p>";
		break;
	}
	case "borrar_evento":
	{
		$query="delete from tcalendario where id='".$_GET["id"]."' limit 1";
		mysql_select_db($dbname);
		if ($resultado=mysql_query($query)) echo "<p class='ok'>Evento eliminado correctamente.</p>";
		else echo "<p class='error'>Se ha producido un error eliminando el evento.</p>";
		break;
	}
	case "generar_calendario":
	{
		$fecha_calendario=array();
		if ($_GET["mes"]=="" || $_GET["anio"]=="")
		{
			$fecha_calendario[1]=intval(date("m"));
			if ($fecha_calendario[1]<10) $fecha_calendario[1]="0".$fecha_calendario[1];
			$fecha_calendario[0]=date("Y");
		}
		else
		{
			$fecha_calendario[1]=intval($_GET["mes"]);
			if ($fecha_calendario[1]<10) $fecha_calendario[1]="0".$fecha_calendario[1];
			else $fecha_calendario[1]=$fecha_calendario[1];
			$fecha_calendario[0]=$_GET["anio"];
		}
		$fecha_calendario[2]="01";
 
		/* obtenemos el dia de la semana del 1 del mes actual */
		$primeromes=date("N",mktime(0,0,0,$fecha_calendario[1],1,$fecha_calendario[0]));
 
		/* comprobamos si el año es bisiesto y creamos array de días */
		if (($fecha_calendario[0] % 4 == 0) && (($fecha_calendario[0] % 100 != 0) || ($fecha_calendario[0] % 400 == 0))) $dias=array("","31","29","31","30","31","30","31","31","30","31","30","31");
		else $dias=array("","31","28","31","30","31","30","31","31","30","31","30","31");
 
		$eventos=array();
 
		$query="select * from tcalendario where month(fecha)='".$fecha_calendario[1]."' and year(fecha)='".$fecha_calendario[0]."'";
		mysql_select_db($dbname);
		$resultado=mysql_query($query);
		if ($fila=mysql_fetch_array($resultado))
		{
			$posicion=0;
			do
			{
				$eventos[$posicion]["id"]=$fila["id"];
				$eventos[$posicion]["fecha"]=$fila["fecha"];
				$eventos[$posicion]["evento"]=$fila["evento"];
				$posicion+=1;
			}
			while($fila=mysql_fetch_array($resultado));
		}
		$meses=array("","Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
 
		/* calculamos los días de la semana anterior al día 1 del mes en curso */
		$diasantes=$primeromes-1;
 
		/* los días totales de la tabla siempre serán máximo 42 (7 días x 6 filas máximo) */
		$diasdespues=42;
 
		/* calculamos las filas de la tabla */
		$tope=$dias[intval($fecha_calendario[1])]+$diasantes;
		if ($tope%7!=0) $totalfilas=intval(($tope/7)+1);
		else $totalfilas=intval(($tope/7));
 
		/* empezamos a pintar la tabla */
		echo "<h2>$nombre Este es el Calendario de Eventos para: ".$meses[intval($fecha_calendario[1])]." de ".$fecha_calendario[0]."</h2>";
		if (isset($mostrar)) echo $mostrar;
 
		echo "<table class='calendario' cellspacing='0' cellpadding='0'>";
			echo "<tr><th>Lunes</th><th>Martes</th><th>Mi&eacute;rcoles</th><th>Jueves</th><th>Viernes</th><th>S&aacute;bado</th><th>Domingo</th></tr><tr>";
 
			/* inicializamos filas de la tabla */
			$tr=0;
			$dia=1;
 
			for ($i=1;$i<=$diasdespues;$i++)
			{
				if ($tr<$totalfilas)
				{
					if ($i>=$primeromes && $i<=$tope)
					{
						echo "<td class='";
						/* creamos fecha completa */
						if ($dia<10) $dia_actual="0".$dia; else $dia_actual=$dia;
						$fecha_completa=$fecha_calendario[0]."-".$fecha_calendario[1]."-".$dia_actual;
 
						if (count($eventos)>0 && buscar_en_array($fecha_completa,$eventos)==true) echo "evento";
 
						/* si es hoy coloreamos la celda */
						if (date("Y-m-d")==$fecha_completa) echo " hoy";
 
						echo "'>";
 
						/* recorremos el array de eventos para mostrar los eventos del día de hoy */
						$total_eventos=count($eventos);
						$eventos_del_dia="";
						for($e=0;$e<$total_eventos;$e++)
						{
							if ($eventos[$e]["fecha"]==$fecha_completa)
							{
								$eventos_del_dia.="<p>".$eventos[$e]["evento"]."<a href='#' class='eliminar_evento' rel='".$eventos[$e]["id"]."' title='Eliminar este Evento del ".fecha($fecha_completa)."'><img src='images/delete.png' /></a></p>";
							}
						}
						if ($eventos_del_dia!="")
						{
							echo "<a href='#' data-evento='#evento".$dia_actual."' class='modal' rel='".$fecha_completa."'>".$dia."</a><div class='window' id='evento".$dia_actual."'>";
								echo "<h2>Eventos del ".fecha($fecha_completa)."</h2><a href='#' class='close' rel='".$fecha_completa."'>Cerrar</a><div class='respuesta'></div>";
								echo $eventos_del_dia;
							echo "</div>";
						}
						else echo "$dia";
						/* agregamos enlace a nuevo evento si la fecha no ha pasado */
						if (date("Y-m-d")<=$fecha_completa) echo "<a href='#' data-evento='#nuevo_evento' title='Agregar un Evento el ".fecha($fecha_completa)."' class='modal agregar_evento' rel='".$fecha_completa."'><img src='images/add.png' /></a>";
 
						echo "</td>";
						$dia+=1;
					}
					else echo "<td class='desactivada'>&nbsp;</td>";
					if ($i==7 || $i==14 || $i==21 || $i==28 || $i==35 || $i==42) {echo "<tr>";$tr+=1;}
				}
			}
			echo "</table>";
 
			echo "<div id='nuevo_evento' class='window'>";
				echo "<h2>Agregar un evento el <span id='que_dia'></span></h2><a href='#' class='close' rel='".$fecha_completa."'>Cerrar</a><div id='respuesta_form'></div>";
				?>
                <form><div align="left">Paciente:
                <label>
 
                    <select name="paciente" id="paciente"></div>
                      <?php
do {
?>
                      <option value="<?php echo $row_Recordset1['apellidos']." ".$row_Recordset1['nombre']?>"><?php echo $row_Recordset1['apellidos']." ".$row_Recordset1['nombre']?></option>
                      <?php
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
  $rows = mysql_num_rows($Recordset1);
  if($rows > 0) {
      mysql_data_seek($Recordset1, 0);
	  $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  }
?>
                    </select>
 
      </label>
				</div>
 
 
			<?php echo "<input type='text' name='evento_titulo' id='evento_titulo'><input type='button' name='Enviar' value='Guardar' class='enviar'><input type='hidden' name='evento_fecha' id='evento_fecha'><br><br>";
 
			echo "</form></div>";
 
			$mesanterior=date("Y-m-d",mktime(0,0,0,$fecha_calendario[1]-1,01,$fecha_calendario[0]));
			$messiguiente=date("Y-m-d",mktime(0,0,0,$fecha_calendario[1]+1,01,$fecha_calendario[0]));
			echo "<p>&laquo; <a href='#' rel='$mesanterior' class='anterior'>Mes Anterior</a> - <a href='#' class='siguiente' rel='$messiguiente'>Mes Siguiente</a> &raquo;</p>";
		break;
	}
}
?>
='editor_line'>
seleccionar paciente.php
 
<?php
require_once('../Connections/myconexion.php');
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }
 
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
 
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
 
mysql_select_db($database_myconexion, $myconexion);
$query_Recordset1 = "SELECT * FROM pacientes_basico ORDER BY nombre ASC";
$Recordset1 = mysql_query($query_Recordset1, $myconexion) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de siREZ
Val: 23
Ha disminuido su posición en 95 puestos en PHP (en relación al último mes)
Gráfica de PHP

solucionado ... problema al guardar en la BBDD

Publicado por siREZ (203 intervenciones) el 05/12/2013 08:24:52
faltaba definir las variables

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$('.enviar').bind("click",function (e)
				{
					e.preventDefault();
					$("#respuesta_form").html("<img src='images/loading.gif'>");
					var evento=$("#evento_titulo").val();
					var observaciones=$("#observaciones").val();
					var paciente=$("#paciente").val();
					var fecha=$("#evento_fecha").val();
					var hora=$("#hora").val();
					$.ajax({
						type: "GET",
						url: "ajax_calendario.php",
						cache: false,
						data: { paciente:paciente,observaciones:observaciones,hora:hora,evento:evento,fecha:fecha,accion:"guardar_evento" }

siREZ
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de xve
Val: 3.943
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

solucionado ... problema al guardar en la BBDD

Publicado por xve (6935 intervenciones) el 05/12/2013 08:30:47
Gracias por comentarlo sIREZ!!!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar