Foros del Web » Programando para Internet » PHP »

En vez de actualizar registro me lo borra =/

Estas en el tema de En vez de actualizar registro me lo borra =/ en el foro de PHP en Foros del Web. Saludos tengo un problema.. actualizando los productos se me borra el registro solo mantiene el id y la imagen... pero lo q es texto lo ...
  #1 (permalink)  
Antiguo 06/02/2008, 14:13
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 8 meses
Puntos: 28
En vez de actualizar registro me lo borra =/

Saludos tengo un problema..
actualizando los productos se me borra el registro
solo mantiene el id y la imagen... pero lo q es texto lo borra... y no entiendo por que :S

Código PHP:
<?php require_once('../Connections/incomed.php'); ?>
<?php
function GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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"] == "form1")) {

if (
$_POST['opcion']==1){
$ediciondir'../images2/';  
$uploaddir=$ediciondir;
if (!
is_dir($ediciondir)) {     mkdir($uploaddir0777);    }
move_uploaded_file($_FILES['imgprinc']['tmp_name'], $uploaddir $_FILES['imgprinc']['name']);    
$filename $_FILES['imgprinc']['name'];}
else {
$filename $_POST['imgprinc'];
}





  
$updateSQL sprintf("UPDATE productos SET titulo=%s, comen=%s, imgprinc=%s WHERE id=%s",
                       
GetSQLValueString($_POST['titulo'], "text"),                       
                       
GetSQLValueString($_POST['comen'], "text"),
                       
GetSQLValueString($filename"text"),
                       
GetSQLValueString($_POST['id'], "int"));

 
mysql_select_db($database_incomed$incomed);
 
$Result1 mysql_query($updateSQL$incomed) or die(mysql_error());

  
$updateGoTo "listado.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$updateGoTo .= (strpos($updateGoTo'?')) ? "&" "?";
    
$updateGoTo .= $_SERVER['QUERY_STRING'];
  }
 
header(sprintf("Location: %s"$updateGoTo));
}

$colname_Recordset1 "1";
if (isset(
$_GET['id'])) {
  
$colname_Recordset1 = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
}
mysql_select_db($database_incomed$incomed);
$query_Recordset1 sprintf("SELECT * FROM productos WHERE id = %s"$colname_Recordset1);
$Recordset1 mysql_query($query_Recordset1$incomed) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);

?>
<html>
<head>
<title>Incomed :: Panel de Actualización</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript" type="text/javascript">
function validar_archivo(archivo) {
    var error_archivo;
    error_archivo=0;
      var file=archivo.value;
      
          if (file=="")
          { error_archivo=1; }
          //texto += "\n\nIngrese Foto"
            else{
             
                 // file=document.formulario.FOTO.value
               extArray = new Array(".gif",".jpg",".swf");
               // Extension de archivos permitidos
               allowSubmit = false;
                 if (!file) return;

                   while (file.indexOf("\\") != -1)
                       file = file.slice(file.indexOf("\\") + 1);
                       ext = file.slice(file.indexOf(".")).toLowerCase();
                   
                   for (var i=0; i < extArray.length; i++){
                          if (extArray[i] == ext){
                             allowSubmit = true;
                             break;
                            }
                    }

                        if (!allowSubmit) {
                         error_archivo=2;
                        // texto += "\n\nFOTO: solo admite archivo con la extensión ''gif, .jpeg , .jpg''";
                         }
                            }
                            return error_archivo;
}



</script>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' es requerido.\n'; }
  } 
  
  var ar;
  var ar, celest;
  ar=document.form1.imagen;
  celest=validar_archivo(ar);
  if (celest==1){errors+="- Imagen es  requerido";}
  if (celest==2){errors+="- Nota: Solo admiten archivos para la imagen con la extensión ''gif, .jpeg , .jpg'";}
  
    if (errors) alert('Han ocurrido los siguientes errores:\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->
</script>
<style type="text/css">td img {display: block;}body {
    background-image: url();
}
</style>
<!--Fireworks CS3 Dreamweaver CS3 target.  Created Thu Jan 31 15:18:44 GMT-0400 2008-->
<link href="../css/estilos.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
a {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 12px;
    font-weight: bold;
}
-->
</style></head>
<body bgcolor="#ffffff">
<table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="770"><table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td><img src="../images/panel_head.jpg" alt="" width="500" height="130" /></td>
      </tr>
    </table></td>
  </tr>
  
  <tr>
    <td valign="top" bgcolor="#CCCCCC"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td align="center" bgcolor="#FFFFFF"><p class="textopanel">&nbsp;</p>
            <p class="textopanel"> Ingresar Productos</p>          <form action="<?php echo $editFormAction?>" method="post" enctype="multipart/form-data" name="form1" onSubmit="MM_validateForm('descripcion','','R');return document.MM_returnValue">
              <table align="center">
                <tr valign="middle">
                  <td width="98" height="21" align="left" nowrap class="tituloINDEX">Codigo</td>
                  <td width="267" align="left"><input name="codigo" type="text" class="textoINDEX" id="codigo" value="<?php echo $row_Recordset1['titulo']; ?>"></td>
                </tr>
                <tr valign="middle">
                  <td height="147" align="left" valign="top" nowrap class="tituloINDEX">Descripcion:</td>
                  <td align="left"><textarea name="descripcion" cols="50" rows="10" class="textoINDEX" ><?php echo $row_Recordset1['comen']; ?></textarea></td>
                </tr>
                <tr valign="middle">
                  <td colspan="2" align="left" nowrap class="Estilo8"><span class="tituloINDEX">Actualizar Imagen?  Si
                    <input name="opcion" type="radio" value="1">
                    /No</span><span class="todopanel">
                    <input name="opcion" type="radio" value="0" checked>
                    <input name="imgprinc" type="hidden" class="todopanel" value="<?php echo $row_Recordset1['imgprinc']; ?>" size="32">
                    <input name="imgprinc" type="file" class="textoINDEX" id="imgprinc">
                    </span></td>
                  </tr>
                <tr valign="middle">
                  <td colspan="2" align="center" nowrap>&nbsp;</td>
                  </tr>
                <tr valign="middle">
                  <td colspan="2" align="left" nowrap> <input type="hidden" name="MM_update" value="form1">
                    <input type="hidden" name="id" value="<?php echo $row_Recordset1['id']; ?>"></td>
                  </tr>
                <tr valign="middle">
                  <td align="left" nowrap>&nbsp;</td>
                  <td align="left"><input name="submit" type="submit" class="descPROD" value="Actualizar registro">                      </td>
                </tr>
                </table>
                </form> </p></td>
        </tr>
      
      <tr>
        <td bgcolor="#FFFFFF"><p align="center"><a href="index.php">Volver al menú</a></p>
          </td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td align="center"><span class="textopie">Incomed, C.A. Todos los derechos reservados 2008.</span></td>
  </tr>
</table>
</body>
</html>
<?php
mysql_free_result
($Recordset1);
?>
__________________
Diseño gráfico, Web, imagen corporativa, publicidad ...
  #2 (permalink)  
Antiguo 06/02/2008, 14:17
Avatar de Akiracr  
Fecha de Ingreso: septiembre-2006
Mensajes: 114
Antigüedad: 17 años, 7 meses
Puntos: 3
Re: En vez de actualizar registro me lo borra =/

GetSQLValueString($_POST['titulo'], "text"),
GetSQLValueString($_POST['comen'], "text"),
GetSQLValueString($filename, "text"),
GetSQLValueString($_POST['id'], "int"));

Verifica que estas variables que vienen en el post no esten vacias, si vienen vacias es porque el nombre del objeto en el form es otro
  #3 (permalink)  
Antiguo 06/02/2008, 14:20
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 8 meses
Puntos: 28
Re: En vez de actualizar registro me lo borra =/

cuando le doy actualizar lee el contenido de la base de datos y cuando actualizo.. me lo borra :S
__________________
Diseño gráfico, Web, imagen corporativa, publicidad ...
  #4 (permalink)  
Antiguo 06/02/2008, 14:22
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 8 meses
Puntos: 28
Re: En vez de actualizar registro me lo borra =/

ok listo... era un error en el form... sorry se me escapo...

y gracias por tu atencion
__________________
Diseño gráfico, Web, imagen corporativa, publicidad ...
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 17:17.