Foros del Web » Programando para Internet » PHP »

Combobox problema

Estas en el tema de Combobox problema en el foro de PHP en Foros del Web. Hola. He creado este combobox con Dreamweaver, y aunque funciona, al cargarse inicialmente aparece un Undifinied Index en la linea 71 y otras. Me podeis ...
  #1 (permalink)  
Antiguo 18/01/2012, 14:33
(Desactivado)
 
Fecha de Ingreso: enero-2004
Mensajes: 136
Antigüedad: 20 años, 3 meses
Puntos: 0
Combobox problema

Hola.

He creado este combobox con Dreamweaver, y aunque funciona, al cargarse inicialmente aparece un Undifinied Index en la linea 71 y otras.

Me podeis ayudar?.

Un saludo.

Código PHP:
Ver original
  1. <?php require_once('Connections/aluxbd.php'); ?>
  2.  <?php
  3.  if (!function_exists("GetSQLValueString")) {
  4.  function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  5. {
  6.  if (PHP_VERSION < 6) {
  7.  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  8.  }
  9.  
  10. $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  11.  
  12. switch ($theType) {
  13.  case "text":
  14.  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  15.  break;
  16. case "long":
  17.  case "int":
  18.  $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  19.  break;
  20.  case "double":
  21.  $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  22.  break;
  23.  case "date":
  24.  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  25.  break;
  26.  case "defined":
  27.  $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  28.  break;
  29.  }
  30.  return $theValue;
  31.  }
  32.  }
  33.  
  34. mysql_select_db($database_aluxbd, $aluxbd);
  35.  $query_ID_AUTONOMIA = "SELECT * FROM autonomia";
  36.  $ID_AUTONOMIA = mysql_query($query_ID_AUTONOMIA, $aluxbd) or die(mysql_error());
  37.  $row_ID_AUTONOMIA = mysql_fetch_assoc($ID_AUTONOMIA);
  38.  $totalRows_ID_AUTONOMIA = mysql_num_rows($ID_AUTONOMIA);
  39.  
  40. $colname_prov = "-1";
  41.  if (isset($_POST['ID_AUTONOMIA'])) {
  42.  $colname_prov = $_POST['ID_AUTONOMIA'];
  43.  }
  44.  mysql_select_db($database_aluxbd, $aluxbd);
  45.  $query_prov = sprintf("SELECT * FROM provincia WHERE ID_AUTONOMIA = %s", GetSQLValueString($colname_prov, "int"));
  46.  $prov = mysql_query($query_prov, $aluxbd) or die(mysql_error());
  47.  $row_prov = mysql_fetch_assoc($prov);
  48.  $totalRows_prov = mysql_num_rows($prov);
  49.  
  50. $colname_poblacion = "-1";
  51.  if (isset($_POST['ID_PROVINCIA'])) {
  52.  $colname_poblacion = $_POST['ID_PROVINCIA'];
  53.  }
  54.  mysql_select_db($database_aluxbd, $aluxbd);
  55.  $query_poblacion = sprintf("SELECT * FROM poblacion WHERE ID_PROVINCIA = %s", GetSQLValueString($colname_poblacion, "int"));
  56.  $poblacion = mysql_query($query_poblacion, $aluxbd) or die(mysql_error());
  57.  $row_poblacion = mysql_fetch_assoc($poblacion);
  58.  $totalRows_poblacion = mysql_num_rows($poblacion);
  59.  ?>
  60.  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  61.  <html xmlns="http://www.w3.org/1999/xhtml">
  62.  <head>
  63.  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  64.  <title>Untitled Document</title>
  65.  </head>
  66.  
  67. <body>
  68.  <form action="" method="post" enctype="multipart/form-data" name="combo" id="combo">
  69.  <label for="ID_AUTONOMIA"></label>
  70.  <select name="ID_AUTONOMIA" id="ID_AUTONOMIA" onChange="submit()">
  71.  <option value="" <?php if (!(strcmp("", $_POST['ID_AUTONOMIA']))) {echo "selected=\"selected\"";} ?>>Autonomia</option>
  72.  <?php
  73.  do {
  74. ?>
  75.  <option value="<?php echo $row_ID_AUTONOMIA['ID_AUTONOMIA']?>"<?php if (!(strcmp($row_ID_AUTONOMIA['ID_AUTONOMIA'], $_POST['ID_AUTONOMIA']))) {echo "selected=\"selected\"";} ?>><?php echo $row_ID_AUTONOMIA['AUTONOMIA']?></option>
  76.  <?php
  77.  } while ($row_ID_AUTONOMIA = mysql_fetch_assoc($ID_AUTONOMIA));
  78.  $rows = mysql_num_rows($ID_AUTONOMIA);
  79.  if($rows > 0) {
  80.  mysql_data_seek($ID_AUTONOMIA, 0);
  81.  $row_ID_AUTONOMIA = mysql_fetch_assoc($ID_AUTONOMIA);
  82.  }
  83.  ?>
  84.  </select>
  85.  <label for="ID_PROVINCIA"></label>
  86.  <select name="ID_PROVINCIA" id="ID_PROVINCIA" onChange="submit()">
  87.  <option value="" <?php if (!(strcmp("", $_POST['ID_PROVINCIA']))) {echo "selected=\"selected\"";} ?>>Provincia</option>
  88.  <?php
  89.  do {
  90. ?>
  91.  <option value="<?php echo $row_prov['ID_PROVINCIA']?>"<?php if (!(strcmp($row_prov['ID_PROVINCIA'], $_POST['ID_PROVINCIA']))) {echo "selected=\"selected\"";} ?>><?php echo $row_prov['PROVINCIA']?></option>
  92.  <?php
  93.  } while ($row_prov = mysql_fetch_assoc($prov));
  94.  $rows = mysql_num_rows($prov);
  95.  if($rows > 0) {
  96.  mysql_data_seek($prov, 0);
  97.  $row_prov = mysql_fetch_assoc($prov);
  98.  }
  99.  ?>
  100.  </select>
  101.  <select name="ID_CIUDAD" id="ID_CIUDAD">
  102.  <option value="" <?php if (!(strcmp("", $_POST['ID_CIUDAD']))) {echo "selected=\"selected\"";} ?>>Poblacion</option>
  103.  <?php
  104.  do {
  105. ?>
  106.  <option value="<?php echo $row_poblacion['ID_CIUDAD']?>"<?php if (!(strcmp($row_poblacion['ID_CIUDAD'], $_POST['ID_CIUDAD']))) {echo "selected=\"selected\"";} ?>><?php echo $row_poblacion['CIUDAD']?></option>
  107.  <?php
  108.  } while ($row_poblacion = mysql_fetch_assoc($poblacion));
  109.  $rows = mysql_num_rows($poblacion);
  110.  if($rows > 0) {
  111.  mysql_data_seek($poblacion, 0);
  112.  $row_poblacion = mysql_fetch_assoc($poblacion);
  113.  }
  114.  ?>
  115.  </select>
  116.  </form>
  117.  </body>
  118.  </html>
  119.  <?php
  120.  mysql_free_result($ID_AUTONOMIA);
  121.  
  122.  
  123. mysql_free_result($poblacion);
  124.  ?>
  #2 (permalink)  
Antiguo 18/01/2012, 14:36
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Combobox problema

Dicho error se explica en el siguiente tema.
http://www.forosdelweb.com/f18/undef...riable-923992/

Te sugiero leer con atención, ahí también se explica la solución.
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #3 (permalink)  
Antiguo 18/01/2012, 17:01
(Desactivado)
 
Fecha de Ingreso: enero-2004
Mensajes: 136
Antigüedad: 20 años, 3 meses
Puntos: 0
Respuesta: Combobox problema

? ? ? ? ? ?
  #4 (permalink)  
Antiguo 18/01/2012, 17:03
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Desacuerdo Respuesta: Combobox problema

Cita:
Iniciado por wayward Ver Mensaje
? ? ? ? ? ?
¿Que sucede?
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #5 (permalink)  
Antiguo 18/01/2012, 18:08
(Desactivado)
 
Fecha de Ingreso: enero-2004
Mensajes: 136
Antigüedad: 20 años, 3 meses
Puntos: 0
Respuesta: Combobox problema

Hola

Este enlace te lleva a la web donde tengo instalado el combobox y funciona correctamente.

http://www.alucinax.com/admin-tools/aut.php

Sin embargo en local me da Undifinied Index.

No entiendo.
  #6 (permalink)  
Antiguo 18/01/2012, 18:12
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Combobox problema

¿Ya leíste el enlace que te sugerí?

De verdad, ahí se explican las causas de dicho error ¿te quieres quedar con la duda?

Si quieres entender debes atender, tu eliges.
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #7 (permalink)  
Antiguo 18/01/2012, 18:15
(Desactivado)
 
Fecha de Ingreso: enero-2004
Mensajes: 136
Antigüedad: 20 años, 3 meses
Puntos: 0
Respuesta: Combobox problema

Si he leido el enlace que me diste.

El problema es que yo no tengo variables sin definir.
  #8 (permalink)  
Antiguo 18/01/2012, 18:20
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Combobox problema

Cita:
Iniciado por wayward Ver Mensaje
Si he leido el enlace que me diste.

El problema es que yo no tengo variables sin definir.
¿Y entonces el mensaje de error que recibes es inventado?

Caray, si el error es evidente es obvio que no comprendes como funciona.

Si quieres muestra el código que tienes y te sabremos refutar lo que aseguras.
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #9 (permalink)  
Antiguo 18/01/2012, 18:38
(Desactivado)
 
Fecha de Ingreso: enero-2004
Mensajes: 136
Antigüedad: 20 años, 3 meses
Puntos: 0
Respuesta: Combobox problema

Este es el codigo.

Y el Undifinied Index da en la linea 77 , 89 y 104

Código PHP:
Ver original
  1. <?php require_once('Connections/aluxbd.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  5. {
  6.   if (PHP_VERSION < 6) {
  7.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  8.   }
  9.  
  10.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  11.  
  12.   switch ($theType) {
  13.     case "text":
  14.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  15.       break;    
  16.     case "long":
  17.     case "int":
  18.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  19.       break;
  20.     case "double":
  21.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  22.       break;
  23.     case "date":
  24.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  25.       break;
  26.     case "defined":
  27.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  28.       break;
  29.   }
  30.   return $theValue;
  31. }
  32. }
  33.  
  34.  
  35.  
  36. mysql_select_db($database_aluxbd, $aluxbd);
  37. $query_ID_AUTONOMIA = "SELECT * FROM autonomia";
  38. $ID_AUTONOMIA = mysql_query($query_ID_AUTONOMIA, $aluxbd) or die(mysql_error());
  39. $row_ID_AUTONOMIA = mysql_fetch_assoc($ID_AUTONOMIA);
  40. $totalRows_ID_AUTONOMIA = mysql_num_rows($ID_AUTONOMIA);
  41.  
  42. $colname_prov = "-1";
  43. if (isset($_POST['ID_AUTONOMIA'])) {
  44.   $colname_prov = $_POST['ID_AUTONOMIA'];
  45. }
  46. mysql_select_db($database_aluxbd, $aluxbd);
  47. $query_prov = sprintf("SELECT * FROM provincia WHERE ID_AUTONOMIA = %s", GetSQLValueString($colname_prov, "int"));
  48. $prov = mysql_query($query_prov, $aluxbd) or die(mysql_error());
  49. $row_prov = mysql_fetch_assoc($prov);
  50. $totalRows_prov = mysql_num_rows($prov);
  51.  
  52. $colname_poblacion = "-1";
  53. if (isset($_POST['ID_PROVINCIA'])) {
  54.   $colname_poblacion = $_POST['ID_PROVINCIA'];
  55. }
  56. mysql_select_db($database_aluxbd, $aluxbd);
  57. $query_poblacion = sprintf("SELECT * FROM poblacion WHERE ID_PROVINCIA = %s", GetSQLValueString($colname_poblacion, "int"));
  58. $poblacion = mysql_query($query_poblacion, $aluxbd) or die(mysql_error());
  59. $row_poblacion = mysql_fetch_assoc($poblacion);
  60. $totalRows_poblacion = mysql_num_rows($poblacion);
  61. ?>
  62. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  63. <html xmlns="http://www.w3.org/1999/xhtml">
  64. <head>
  65. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  66. <title>Combobox</title>
  67. </head>
  68.  
  69. <body>
  70. <form action="" method="post" enctype="application/x-www-form-urlencoded" name="combo" id="combo">
  71.   <label for="ID_AUTONOMIA"></label>
  72.   <select name="ID_AUTONOMIA" id="ID_AUTONOMIA" onChange="submit()">
  73.     <option value="">Autonomia</option>
  74.     <?php
  75. do {  
  76. ?>
  77. <option value="<?php echo $row_ID_AUTONOMIA['ID_AUTONOMIA']?>"<?php if (!(strcmp($row_ID_AUTONOMIA['ID_AUTONOMIA'], $_POST['ID_AUTONOMIA']))) {echo "selected=\"selected\"";} ?>><?php echo $row_ID_AUTONOMIA['AUTONOMIA']?></option>
  78.     <?php
  79. } while ($row_ID_AUTONOMIA = mysql_fetch_assoc($ID_AUTONOMIA));
  80.   $rows = mysql_num_rows($ID_AUTONOMIA);
  81.   if($rows > 0) {
  82.       mysql_data_seek($ID_AUTONOMIA, 0);
  83.       $row_ID_AUTONOMIA = mysql_fetch_assoc($ID_AUTONOMIA);
  84.   }
  85. ?>
  86.   </select>
  87.   <label for="ID_PROVINCIA"></label>
  88.   <select name="ID_PROVINCIA" id="ID_PROVINCIA" onChange="submit()">
  89.     <option value="" <?php if (!(strcmp("", $_POST['ID_PROVINCIA']))) {echo "selected=\"selected\"";} ?>>Provincia</option>
  90.     <?php
  91. do {  
  92. ?>
  93.     <option value="<?php echo $row_prov['ID_PROVINCIA']?>"<?php if (!(strcmp($row_prov['ID_PROVINCIA'], $_POST['ID_PROVINCIA']))) {echo "selected=\"selected\"";} ?>><?php echo $row_prov['PROVINCIA']?></option>
  94.     <?php
  95. } while ($row_prov = mysql_fetch_assoc($prov));
  96.   $rows = mysql_num_rows($prov);
  97.   if($rows > 0) {
  98.       mysql_data_seek($prov, 0);
  99.       $row_prov = mysql_fetch_assoc($prov);
  100.   }
  101. ?>
  102.   </select>
  103.   <select name="ID_CIUDAD" id="ID_CIUDAD">
  104.     <option value="" <?php if (!(strcmp("", $_POST['ID_CIUDAD']))) {echo "selected=\"selected\"";} ?>>Poblacion</option>
  105.     <?php
  106. do {  
  107. ?>
  108.     <option value="<?php echo $row_poblacion['ID_CIUDAD']?>"<?php if (!(strcmp($row_poblacion['ID_CIUDAD'], $_POST['ID_CIUDAD']))) {echo "selected=\"selected\"";} ?>><?php echo $row_poblacion['CIUDAD']?></option>
  109.     <?php
  110. } while ($row_poblacion = mysql_fetch_assoc($poblacion));
  111.   $rows = mysql_num_rows($poblacion);
  112.   if($rows > 0) {
  113.       mysql_data_seek($poblacion, 0);
  114.       $row_poblacion = mysql_fetch_assoc($poblacion);
  115.   }
  116. ?>
  117.   </select>
  118. </form>
  119. </body>
  120. </html>
  121. <?php
  122. mysql_free_result($ID_AUTONOMIA);
  123.  
  124.  
  125. mysql_free_result($poblacion);
  126. ?>
  #10 (permalink)  
Antiguo 18/01/2012, 18:42
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Combobox problema

¿Quieres compartir también los mensajes de error completos que recibes?
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #11 (permalink)  
Antiguo 18/01/2012, 18:50
(Desactivado)
 
Fecha de Ingreso: enero-2004
Mensajes: 136
Antigüedad: 20 años, 3 meses
Puntos: 0
Respuesta: Combobox problema

Linea 77 Undefinied index ID_AUTONOMIA on line 77

Linea 89 Undifined Index ID_PROVINCIA selected="selected" line 89
  #12 (permalink)  
Antiguo 18/01/2012, 18:53
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Combobox problema

Ahora, ¿el error ocurre siempre o sólo la primer vez que cargas el formulario?

Según se explica en el tema que te pase antes no puedes leer variables que no existen, es claro que en las lineas del error estás leyendo variables de $_POST pero dichas variables solo existen cuando existe un envio de formulario de método post.

Si no hay post entonces no hay $_POST, así de simple.

Debes validar tus variables antes de usarlas, siempre.
Código PHP:
$ID_CIUDAD = isset($_POST['ID_CIUDAD']) ? $_POST['ID_CIUDAD'] : NULL
Y después usar dicha varuable $ID_CIUDAD en lugar de $_POST['ID_CIUDAD'] ¿se entiende tu error ahora?
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #13 (permalink)  
Antiguo 18/01/2012, 18:57
(Desactivado)
 
Fecha de Ingreso: enero-2004
Mensajes: 136
Antigüedad: 20 años, 3 meses
Puntos: 0
Respuesta: Combobox problema

Hola.

Solo ocurre cuando se carga por primera vez la pagina.
  #14 (permalink)  
Antiguo 18/01/2012, 18:59
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Combobox problema

Cita:
Iniciado por wayward Ver Mensaje
[...] Solo ocurre cuando se carga por primera vez la pagina.
Pues ese es exactamente tu problema.

Edite mi respuesta anterior, y por favor lee dos veces el tema que te enlacé al inicio, ahí está explicado perfectamente el problema y solución.
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #15 (permalink)  
Antiguo 18/01/2012, 19:05
(Desactivado)
 
Fecha de Ingreso: enero-2004
Mensajes: 136
Antigüedad: 20 años, 3 meses
Puntos: 0
Respuesta: Combobox problema

Gracias por la ayuda.

He realizado lo que me has comentado, y ahora me sale otro error:

strcmp() excepets parameter 2 to be string. resource given in aut.php on line 74 selected="selected"
  #16 (permalink)  
Antiguo 18/01/2012, 19:25
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Combobox problema

Pues el error dice que no le estás pasando una cadena, ¿como lo estás haciendo?
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.

Etiquetas: combobox, html, mysql, sql
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 13:11.