PHP - Al enviar solo inserta parte del formulario en mySQL

 
Vista:
sin imagen de perfil

Al enviar solo inserta parte del formulario en mySQL

Publicado por Sindy (7 intervenciones) el 15/03/2015 20:00:05
Buenas tardes.. amigos tengo un problema al que no le he podido encontrar solucion y el siguiente:

Tengo una base de datos con 4 tablas, la principal tiene un campo autoincrement, yo las alimento por medio de un formulario, la idea es que cuando envie la informacion se llene un registro de cada tabla. Las otras tres tablas por medio de LAST_insert_ID() las relaciono con las primera, para poder recuperar informacion... El problema es que cuando inserto solo parte del formulario y que quedan campos no NULL sin llenar SQL me avisa que no puede ser no NULL y cuando regreso a corregir, me doy cuenta que ya la informacion esta ene la base de datos por que al completar me dice que las pk estan duplicadas... Al ir a la base de datos, me consigo que se lleno solo la primera tabla, donde se encuentra la cedula del estudiante que es pk... y las otras tablas estan vacias... Obviamente ya se me pierde la relacion de los registros.. Por favor, alguien puede decirme que puedo hacer para solucionar este problema??

este es el scritp

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
<?php require_once('Connections/local.php'); ?>
<?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;
}
}
 
$currentPage = $_SERVER["PHP_SELF"];
 
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
 
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {
  $insertSQL = sprintf("INSERT INTO datosestudiantes (ciestudiantes, nombre1, nombre2, apellido1, apellido2, sexo, edad, fechaNac, lugarNac, direccion, telefono, celular, email, foto) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['txCedula'], "int"),
                       GetSQLValueString($_POST['txNombre1'], "text"),
                       GetSQLValueString($_POST['txNombre2'], "text"),
                       GetSQLValueString($_POST['txApellido1'], "text"),
                       GetSQLValueString($_POST['txApellido2'], "text"),
                       GetSQLValueString($_POST['txSexo'], "text"),
                       GetSQLValueString($_POST['txEdad'], "int"),
                       GetSQLValueString($_POST['txFecha'], "date"),
                       GetSQLValueString($_POST['txLugarNac'], "text"),
                       GetSQLValueString($_POST['txDireccion'], "text"),
                       GetSQLValueString($_POST['txTelefono'], "text"),
                       GetSQLValueString($_POST['txCelular'], "text"),
                       GetSQLValueString($_POST['txEmail'], "text"),
                       GetSQLValueString($_POST['txfoto'], "text"));
 
 
$insertSQL1= sprintf("INSERT INTO datosrepresentantes (reID,cirepresentante, nombre1, nombre2, apellido1, apellido2, sexo, fechaNac, edad, lugarNac, profesion, telefono, celular, email, parentezco, direccion,ubicacionsf) VALUES (LAST_INSERT_ID(),%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,%s)",
                       GetSQLValueString($_POST['txRcedula'], "int"),
                       GetSQLValueString($_POST['txRnombre'], "text"),
                       GetSQLValueString($_POST['txRnombre2'], "text"),
                       GetSQLValueString($_POST['txRapellido1'], "text"),
                       GetSQLValueString($_POST['txRapellido2'], "text"),
                       GetSQLValueString($_POST['lsRsexo'], "text"),
                       GetSQLValueString($_POST['txRfecha'], "date"),
                       GetSQLValueString($_POST['txRedad'], "int"),
                       GetSQLValueString($_POST['txRlugarnac'], "text"),
                       GetSQLValueString($_POST['txRprofesion'], "text"),
                       GetSQLValueString($_POST['txRtelefono'], "text"),
                       GetSQLValueString($_POST['txRcelular'], "text"),
                       GetSQLValueString($_POST['txRemail'], "text"),
                       GetSQLValueString($_POST['txRparentezco'], "text"),
			   GetSQLValueString(
$_POST['txRubicacionsf'], "text"),
                       GetSQLValueString($_POST['txRdireccion'], "text"));
 
$insertSQL2 = sprintf("INSERT INTO datosacademicos (acID, programaAca, especialidadOcu, becas) VALUES (LAST_INSERT_ID(),%s, %s, %s)",
                       GetSQLValueString($_POST['lsPrograma'], "int"),
                       GetSQLValueString($_POST['lsEspecialidadOcup'], "text"),
                       GetSQLValueString($_POST['lsBecas'], "text"));
 
$insertSQL3 = sprintf("INSERT INTO datosmedicos (meID,condicion, condicionAsc, medidasantro, tallas, medicamento, medicotratante, telefono) VALUES (LAST_INSERT_ID(),%s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['txCondicion'], "text"),
                       GetSQLValueString($_POST['txCondicionasoc'], "text"),
                       GetSQLValueString($_POST['txMedidasantropo'], "text"),
                       GetSQLValueString($_POST['lsTalla'], "text"),
                       GetSQLValueString($_POST['ltxmedicamentos'], "text"),
                       GetSQLValueString($_POST['lsMedicotratante'], "text"),
                       GetSQLValueString($_POST['txMtelefonos:'], "text"));
 
 
 
 mysql_select_db($database_local, $local);
  $Result1 = mysql_query($insertSQL, $local)  and mysql_query($insertSQL1, $local) and mysql_query($insertSQL2, $local) and mysql_query($insertSQL3, $local)
 
  or die(mysql_error());
}
?>
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