Foros del Web » Programando para Internet » PHP »

problema al editar formulario

Estas en el tema de problema al editar formulario en el foro de PHP en Foros del Web. Estimados, tengo un problema, desde un boton en una tabla dinamica llamo a edicion un formulario, este se muestra y puedo editarlo sin problemas, hasta ...
  #1 (permalink)  
Antiguo 07/02/2012, 12:15
 
Fecha de Ingreso: noviembre-2011
Mensajes: 121
Antigüedad: 12 años, 5 meses
Puntos: 0
problema al editar formulario

Estimados, tengo un problema, desde un boton en una tabla dinamica llamo a edicion un formulario, este se muestra y puedo editarlo sin problemas, hasta ahi, todo bien...

El problema se da es que, todos los certificados del mismo grupo toman la edicion del certificado modificado, es decir, todos los certificados quedan iguales...

No puedo pegar el codigo de la pagina que hace la modificacion, asi que les doy la direccion para que puedan verlo:

http://www.optchile.cl/modificar_formulario.php
  #2 (permalink)  
Antiguo 07/02/2012, 12:28
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 10 meses
Puntos: 2135
Respuesta: problema al editar formulario

Necesitamos ver el código fuente, por lo que dices es probable que le falte la clausula WHERE a tu UPDATE y es por eso que esta tomando todos los valores.

Saludos.
  #3 (permalink)  
Antiguo 07/02/2012, 12:30
Avatar de jotaincubus  
Fecha de Ingreso: mayo-2005
Ubicación: Medellin - Colombia
Mensajes: 1.797
Antigüedad: 18 años, 11 meses
Puntos: 394
Respuesta: problema al editar formulario

Muy bonito tu formulario, pero recuerda que PHP no es visible ya que este solo entrega respuestas HTML, así que no podemos hacer nada de nada ya que no vemos tu codigo.

De otro lado si mal no entiendo, lo que sucede es que al llamar la acción todos los registros de la base de datos se están modificando, cuando en la realidad solo quieres modificar el registro seleccionado....

Si esto es así deberás pasar el identificador del registro del certificado a modificar, puedes hacerlo con parámetros url así:

pagina.php?id=1

en la pagina que procesa los datos simplemente tomas ese ID y haces un update con la clausula WHERE de MySql

UPDATE tbl_nombre SET campo = valor WHERE id=$id;

Espero te sirva de ayuda...
__________________
Por que existe gente que no agradece después de que se le ha brindado tiempo y ayuda ???
  #4 (permalink)  
Antiguo 07/02/2012, 12:37
 
Fecha de Ingreso: noviembre-2011
Mensajes: 121
Antigüedad: 12 años, 5 meses
Puntos: 0
Respuesta: problema al editar formulario

Tendre que poner el codigo en 3 o 4 post, la idea era que pudieran bajar el archivo para ver el codigo... pero no hay problemas...

Como dices, esa es solo la pagina, el ?numcer=x da el certificado que quiero modificar...
  #5 (permalink)  
Antiguo 07/02/2012, 12:38
 
Fecha de Ingreso: noviembre-2011
Mensajes: 121
Antigüedad: 12 años, 5 meses
Puntos: 0
Respuesta: problema al editar formulario

Código PHP:
<?php require_once('Connections/localhost.php'); ?>
<?php 
require_once('Connections/formulario.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;
}
}

$editFormAction $_SERVER['PHP_SELF'];
if (isset(
$_SERVER['QUERY_STRING'])) {
  
$editFormAction .= "?" htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset(
$_POST["MM_update"])) && ($_POST["MM_update"] == "f1")) {
  
$updateSQL sprintf("UPDATE cert SET poblacion=%s, calle=%s, n=%s, tipo_recinto=%s, n1=%s, pisos=%s, tipo_gas=%s, empresa=%s, artefacto=%s, tipo_artefacto=%s, marca=%s, modelo=%s, n_serie=%s, potencia=%s, ubicacion=%s, volumen=%s, encendido=%s, con_gas=%s, con_agua=%s, comandos=%s, quemadores=%s, conducto_2=%s, sellac2_uni=%s, diseno_mat_c2=%s, carcasa=%s, conjunto_piloto=%s, inter_calor=%s, sist_seguridad=%s, co_corr_ppc_antes=%s, co_corr_ppc_despues=%s, co_amb_ppm_antes=%s, co_amb_ppm_despues=%s, tiro_antes=%s, tiro_despues=%s, cau_agua_f_antes=%s, cau_agua_f_despues=%s, t_agua_f_antes=%s, t_agua_f_despues=%s, cau_agua_t_antes=%s, cau_agua_t_despues=%s, t_agua_t_antes=%s, t_agua_t_despues=%s, valvula_gas=%s, valvula_agua=%s, sensor_revoco=%s, sensor_temp=%s, bobina=%s, red_gas=%s, artefactos=%s, observaciones=%s, nombre=%s, rut1=%s, tel_fijo=%s, tel_celular=%s, correo=%s, obs_de_recep=%s WHERE cod_ver=%s",
                       
GetSQLValueString($_POST['poblacion'], "text"),
                       
GetSQLValueString($_POST['calle'], "text"),
                       
GetSQLValueString($_POST['n'], "text"),
                       
GetSQLValueString($_POST['tipo_recinto'], "text"),
                       
GetSQLValueString($_POST['n1'], "text"),
                       
GetSQLValueString($_POST['pisos'], "text"),
                       
GetSQLValueString($_POST['tipo_gas'], "text"),
                       
GetSQLValueString($_POST['empresa'], "text"),
                       
GetSQLValueString($_POST['artefacto'], "text"),
                       
GetSQLValueString($_POST['tipo_artefacto'], "text"),
                       
GetSQLValueString($_POST['marca'], "text"),
                       
GetSQLValueString($_POST['modelo'], "text"),
                       
GetSQLValueString($_POST['n_serie'], "text"),
                       
GetSQLValueString($_POST['potencia'], "text"),
                       
GetSQLValueString($_POST['ubicacion'], "text"),
                       
GetSQLValueString($_POST['volumen'], "text"),
                       
GetSQLValueString($_POST['encendido'], "text"),
                       
GetSQLValueString($_POST['con_gas'], "text"),
                       
GetSQLValueString($_POST['con_agua'], "text"),
                       
GetSQLValueString($_POST['comandos'], "text"),
                       
GetSQLValueString($_POST['quemadores'], "text"),
                       
GetSQLValueString($_POST['conducto_2'], "text"),
                       
GetSQLValueString($_POST['sellac2_uni'], "text"),
                       
GetSQLValueString($_POST['diseno_mat_c2'], "text"),
                       
GetSQLValueString($_POST['carcasa'], "text"),
                       
GetSQLValueString($_POST['conjunto_piloto'], "text"),
                       
GetSQLValueString($_POST['inter_calor'], "text"),
                       
GetSQLValueString($_POST['sist_seguridad'], "text"),
                       
GetSQLValueString($_POST['co_corr_ppc_antes'], "text"),
                       
GetSQLValueString($_POST['co_corr_ppc_despues'], "text"),
                       
GetSQLValueString($_POST['co_amb_ppm_antes'], "text"),
                       
GetSQLValueString($_POST['co_amb_ppm_despues'], "text"),
                       
GetSQLValueString($_POST['tiro_antes'], "text"),
                       
GetSQLValueString($_POST['tiro_despues'], "text"),
                       
GetSQLValueString($_POST['cau_agua_f_antes'], "text"),
                       
GetSQLValueString($_POST['cau_agua_f_despues'], "text"),
                       
GetSQLValueString($_POST['t_agua_f_antes'], "text"),
                       
GetSQLValueString($_POST['t_agua_f_despues'], "text"),
                       
GetSQLValueString($_POST['cau_agua_t_antes'], "text"),
                       
GetSQLValueString($_POST['cau_agua_t_despues'], "text"),
                       
GetSQLValueString($_POST['t_agua_t_antes'], "text"),
                       
GetSQLValueString($_POST['t_agua_t_despues'], "text"),
                       
GetSQLValueString($_POST['valvula_gas'], "text"),
                       
GetSQLValueString($_POST['valvula_agua'], "text"),
                       
GetSQLValueString($_POST['sensor_revoco'], "text"),
                       
GetSQLValueString($_POST['sensor_temp'], "text"),
                       
GetSQLValueString($_POST['bobina'], "text"),
                       
GetSQLValueString($_POST['red_gas'], "text"),
                       
GetSQLValueString($_POST['artefactos'], "text"),
                       
GetSQLValueString($_POST['observaciones'], "text"),
                       
GetSQLValueString($_POST['nombre'], "text"),
                       
GetSQLValueString($_POST['rut1'], "text"),
                       
GetSQLValueString($_POST['tel_fijo'], "text"),
                       
GetSQLValueString($_POST['tel_celular'], "text"),
                       
GetSQLValueString($_POST['correo'], "text"),
                       
GetSQLValueString($_POST['obs_de_recep'], "text"),
                       
GetSQLValueString($_POST['cod_ver'], "text"));
  #6 (permalink)  
Antiguo 07/02/2012, 12:39
 
Fecha de Ingreso: noviembre-2011
Mensajes: 121
Antigüedad: 12 años, 5 meses
Puntos: 0
Respuesta: problema al editar formulario

Código PHP:

  mysql_select_db
($database_localhost$localhost);
  
$Result1 mysql_query($updateSQL$localhost) or die(mysql_error());
}

$colname_editar "-1";
if (isset(
$_GET['numcert'])) {
  
$colname_editar $_GET['numcert'];
}
mysql_select_db($database_localhost$localhost);
$query_editar sprintf("SELECT * FROM cert WHERE ncert = %s"GetSQLValueString($colname_editar"int"));
$editar mysql_query($query_editar$localhost) or die(mysql_error());
$row_editar mysql_fetch_assoc($editar);

mysql_select_db($database_localhost$localhost);
$query_proy "SELECT * FROM proyectos";
$proy mysql_query($query_proy$localhost) or die(mysql_error());
$row_proy mysql_fetch_assoc($proy);
$totalRows_proy mysql_num_rows($proy);

mysql_select_db($database_formulario$formulario);
$query_recinto "SELECT * FROM recintos ORDER BY recinto ASC";
$recinto mysql_query($query_recinto$formulario) or die(mysql_error());
$row_recinto mysql_fetch_assoc($recinto);
$totalRows_recinto mysql_num_rows($recinto);

mysql_select_db($database_formulario$formulario);
$query_tipo_gas "SELECT * FROM tipo_gas ORDER BY tipo_gas ASC";
$tipo_gas mysql_query($query_tipo_gas$formulario) or die(mysql_error());
$row_tipo_gas mysql_fetch_assoc($tipo_gas);
$totalRows_tipo_gas mysql_num_rows($tipo_gas);

mysql_select_db($database_formulario$formulario);
$query_conducto2 "SELECT * FROM conducto_2 ORDER BY conducto_2 ASC";
$conducto2 mysql_query($query_conducto2$formulario) or die(mysql_error());
$row_conducto2 mysql_fetch_assoc($conducto2);
$totalRows_conducto2 mysql_num_rows($conducto2);

mysql_select_db($database_formulario$formulario);
$query_cumple "SELECT * FROM cumple ORDER BY id ASC";
$cumple mysql_query($query_cumple$formulario) or die(mysql_error());
$row_cumple mysql_fetch_assoc($cumple);
$totalRows_cumple mysql_num_rows($cumple);

mysql_select_db($database_formulario$formulario);
$query_empresa "SELECT * FROM empresa ORDER BY empresa_gas ASC";
$empresa mysql_query($query_empresa$formulario) or die(mysql_error());
$row_empresa mysql_fetch_assoc($empresa);
$totalRows_empresa mysql_num_rows($empresa);

mysql_select_db($database_formulario$formulario);
$query_marca "SELECT * FROM marcas ORDER BY marca ASC";
$marca mysql_query($query_marca$formulario) or die(mysql_error());
$row_marca mysql_fetch_assoc($marca);
$totalRows_marca mysql_num_rows($marca);

mysql_select_db($database_formulario$formulario);
$query_modelo "SELECT * FROM modelos ORDER BY modelo ASC";
$modelo mysql_query($query_modelo$formulario) or die(mysql_error());
$row_modelo mysql_fetch_assoc($modelo);
$totalRows_modelo mysql_num_rows($modelo);

mysql_select_db($database_localhost$localhost);
$query_proyectos "SELECT proy FROM proyectos ORDER BY proy ASC";
$proyectos mysql_query($query_proyectos$localhost) or die(mysql_error());
$row_proyectos mysql_fetch_assoc($proyectos);
$totalRows_proyectos mysql_num_rows($proyectos);

mysql_select_db($database_formulario$formulario);
$query_artefacto "SELECT * FROM nombre_artefacto ORDER BY nombre_artefacto ASC";
$artefacto mysql_query($query_artefacto$formulario) or die(mysql_error());
$row_artefacto mysql_fetch_assoc($artefacto);
$totalRows_artefacto mysql_num_rows($artefacto);

mysql_select_db($database_formulario$formulario);
$query_ubicacion "SELECT * FROM ubicacion ORDER BY ubicacion ASC";
$ubicacion mysql_query($query_ubicacion$formulario) or die(mysql_error());
$row_ubicacion mysql_fetch_assoc($ubicacion);
$totalRows_ubicacion mysql_num_rows($ubicacion);

mysql_select_db($database_formulario$formulario);
$query_encendido "SELECT * FROM tipo_encendido ORDER BY tipo_encendido ASC";
$encendido mysql_query($query_encendido$formulario) or die(mysql_error());
$row_encendido mysql_fetch_assoc($encendido);
$totalRows_encendido mysql_num_rows($encendido);

$colname_ediat "-1";
if (isset(
$_GET['numcert'])) {
  
$colname_ediat $_GET['numcert'];
}
mysql_select_db($database_localhost$localhost);
$query_ediat sprintf("SELECT * FROM cert WHERE ncert = %s"GetSQLValueString($colname_ediat"int"));
$ediat mysql_query($query_ediat$localhost) or die(mysql_error());
$row_ediat mysql_fetch_assoc($ediat);
$totalRows_ediat mysql_num_rows($ediat);

$colname_edicion "-1";
if (isset(
$_GET['numcert'])) {
  
$colname_edicion $_GET['numcert'];
}
mysql_select_db($database_localhost$localhost);
$query_edicion sprintf("SELECT * FROM cert WHERE ncert = %s"GetSQLValueString($colname_edicion"int"));
$edicion mysql_query($query_edicion$localhost) or die(mysql_error());
$row_edicion mysql_fetch_assoc($edicion);
?> 
  #7 (permalink)  
Antiguo 07/02/2012, 12:42
 
Fecha de Ingreso: noviembre-2011
Mensajes: 121
Antigüedad: 12 años, 5 meses
Puntos: 0
Respuesta: problema al editar formulario

Ese es todo el codigo que va a antes de la etiqueta del html...

La pagina esta hecha en Dreamweaver, y nunca me habia dado ningun problema...

Si se necesita el codigo del formulario completo puedo agregarlo...
  #8 (permalink)  
Antiguo 07/02/2012, 12:43
Avatar de jotaincubus  
Fecha de Ingreso: mayo-2005
Ubicación: Medellin - Colombia
Mensajes: 1.797
Antigüedad: 18 años, 11 meses
Puntos: 394
Respuesta: problema al editar formulario

Y en la sentencia UPDATE donde esta la clausula WHERE ? esa es exactamente la razón por la cual te hace UPDATE a todos los registros
__________________
Por que existe gente que no agradece después de que se le ha brindado tiempo y ayuda ???
  #9 (permalink)  
Antiguo 07/02/2012, 13:05
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 10 meses
Puntos: 2135
Respuesta: problema al editar formulario

Pues no se ve nada extraño en tu código, más que usas el código verificador, revisa que no estes pasandole un campo vacio a cod_ver ya que puede que te cause un problema.

Saludos.
  #10 (permalink)  
Antiguo 07/02/2012, 13:19
Avatar de jotaincubus  
Fecha de Ingreso: mayo-2005
Ubicación: Medellin - Colombia
Mensajes: 1.797
Antigüedad: 18 años, 11 meses
Puntos: 394
Respuesta: problema al editar formulario

Cita:
Iniciado por jotaincubus Ver Mensaje
Y en la sentencia UPDATE donde esta la clausula WHERE ? esa es exactamente la razón por la cual te hace UPDATE a todos los registros
Que ceguera la mía.... que pena ya lo vi, haz lo que te dice @GatorV y pon un echo a $cod_ver para ver si esta tomando el valor.
__________________
Por que existe gente que no agradece después de que se le ha brindado tiempo y ayuda ???
  #11 (permalink)  
Antiguo 07/02/2012, 13:20
 
Fecha de Ingreso: noviembre-2011
Mensajes: 121
Antigüedad: 12 años, 5 meses
Puntos: 0
Respuesta: problema al editar formulario

Cita:
Iniciado por jotaincubus Ver Mensaje
Y en la sentencia UPDATE donde esta la clausula WHERE ? esa es exactamente la razón por la cual te hace UPDATE a todos los registros
Aqui esta:

Código:
UPDATE cert SET poblacion=%s, calle=%s, n=%s, tipo_recinto=%s, n1=%s, pisos=%s, tipo_gas=%s, empresa=%s, 
artefacto=%s, tipo_artefacto=%s, marca=%s, modelo=%s, n_serie=%s, potencia=%s, ubicacion=%s, volumen=%s, encendido=%s, 
con_gas=%s, con_agua=%s, comandos=%s, quemadores=%s, conducto_2=%s, sellac2_uni=%s, diseno_mat_c2=%s, carcasa=%s, 
conjunto_piloto=%s, inter_calor=%s, sist_seguridad=%s, co_corr_ppc_antes=%s, co_corr_ppc_despues=%s, co_amb_ppm_antes=%s, 
co_amb_ppm_despues=%s, tiro_antes=%s, tiro_despues=%s, cau_agua_f_antes=%s, cau_agua_f_despues=%s, t_agua_f_antes=%s, 
t_agua_f_despues=%s, cau_agua_t_antes=%s, cau_agua_t_despues=%s, t_agua_t_antes=%s, t_agua_t_despues=%s, valvula_gas=%s, 
valvula_agua=%s, sensor_revoco=%s, sensor_temp=%s, bobina=%s, red_gas=%s, artefactos=%s, observaciones=%s, nombre=%s, rut1=%s, 
tel_fijo=%s, tel_celular=%s, correo=%s, obs_de_recep=%s WHERE cod_ver=
  #12 (permalink)  
Antiguo 07/02/2012, 13:29
 
Fecha de Ingreso: noviembre-2011
Mensajes: 121
Antigüedad: 12 años, 5 meses
Puntos: 0
Respuesta: problema al editar formulario

lo que me hace dudar es pq el cod_ver esta despues del where, si se supone que cod_ver no tiene ninguna implicancia en el certificado... y para mi el unico dato que no puede cambiar es el ncert...

insisto, hice el formulario por dreamweaver...
  #13 (permalink)  
Antiguo 07/02/2012, 13:36
 
Fecha de Ingreso: noviembre-2011
Mensajes: 121
Antigüedad: 12 años, 5 meses
Puntos: 0
Respuesta: problema al editar formulario

lo solucione.... era eso, en vez del con_ver debia decir ncert.... MUCHAS GRACIAS!!!!!!!!!!!!!!!!!!!!!
  #14 (permalink)  
Antiguo 07/02/2012, 14:09
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 10 meses
Puntos: 2135
Respuesta: problema al editar formulario

Dreamweaver no debe de hacer nada, sin que tú se lo indiques, es por eso que siempre es mucho mejor escribir tú el código a dejar que Dreamweaver lo haga por tí.

Etiquetas: formulario, tabla
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 12:55.