Foros del Web » Programando para Internet » PHP »

[SOLUCIONADO] Undefined variable:XXXX Problema

Estas en el tema de Undefined variable:XXXX Problema en el foro de PHP en Foros del Web. Hola amigos estoy tratando de actualizar un campo en un formulario y me aparece lo siguiente: Notice: Undefined variable: fondo in /Applications/MAMP/htdocs/tienda/php_guardar_producto.php on line 26 ...
  #1 (permalink)  
Antiguo 19/04/2013, 23:30
 
Fecha de Ingreso: abril-2013
Mensajes: 34
Antigüedad: 11 años
Puntos: 0
Pregunta Undefined variable:XXXX Problema

Hola amigos estoy tratando de actualizar un campo en un formulario y me aparece lo siguiente:

Notice: Undefined variable: fondo in /Applications/MAMP/htdocs/tienda/php_guardar_producto.php on line 26

Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/tienda/php_guardar_producto.php:26) in /Applications/MAMP/htdocs/tienda/php_guardar_producto.php on line 29


Tengo dos archivos en donde esta el corigo el primero es donde esta mi formulario que es este:

Código PHP:
 <?php session_start(); 
    
        if(
$_SESSION['username']==""){ 
            
header('location:index.php');
        }else{
            if(
$_SESSION['tipo_usu']=='a'){
            }else{
                
header('location:index.php');
            }
        }
        include(
'php_conexion.php');
        
$nom="";$des="";$est="s";
        if(empty(
$_GET['codigo'])){
             
$can=mysql_query("SELECT MAX(id) as codigo FROM productos");
             if(
$dato=mysql_fetch_array($can)){
                
$codigo=$dato['codigo']+1
              }
        }else{
            
$codigo=$_GET['codigo'];
            
$can=mysql_query("SELECT * FROM productos WHERE id=$codigo");
             if(
$datos=mysql_fetch_array($can)){
                
$nom=$datos['nom']; 
                
$des=$datos['des'];
                
$est=$datos['estado'];
                
$fondo=$datos['fondo'];
              }
        }
         
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
<title>Editar Metodos de Pagos</title>
<script type="text/javascript" src="js/jquery.js"></script>    
<link href="css/bootstrap.css" rel="stylesheet">
<link href="css/whmcs.css" rel="stylesheet">

<style type="text/css">
body {
    background-color: #FFFFFF;
}
</style>
<script src="js/whmcs.js"></script>
</head>
<body>
<div class="whmcscontainer">
       <div class="contentpadded">
        <div class="page-header">
            <div class="styled_title">
              <h1>Nuevo Producto</h1></div>
        </div>
     <form action="php_guardar_producto.php" method="post" enctype="multipart/form-data">
     <table width="100%" border="0">
         <tr>
           <td><p>Codigo del Producto: <?php echo $codigo?><input type="hidden" name="codigo" id="codigo" value="<?php echo $codigo?>"></p></td>
           <td width="56%" rowspan="3"><table width="100%" border="0">
             <tr>
               <td><div align="center">
                 <?php    
              
if (file_exists("foto/".$codigo.".jpg")){ 
                      echo 
'<div align="center"><img src="foto/'.$codigo.'.jpg" width="229" height="228" alt=""></div>';
              }else{ 
                      echo 
'<div align="center"><img src="foto/defecto.png" width="229" height="228" alt=""></div>';
              } 
              
?>
               </div></td>
             </tr>
             <tr>
               <td>
                <input name="imagen" id="imagen" type="file" class="ui-state-error" size="20" />
            </td>
             </tr>
           </table></td>
      </tr>
         <tr>
           <td width="44%"><p>Unidad Administrativa: <br> <input type="text" name="nom" id="nom" value="<?php echo $nom?>"></p>
        <p>Fondo: <br> <input type="text" name="fondo" id="fondo" value="<?php echo $fondo?>"></p></td>
           </tr>
         <tr>
           <td><p>
            Descripcion : <br> <textarea name="des" rows="4" id="des"><?php echo $des?></textarea></p>
             <p>&nbsp;</p>
             <p>Estado : 
               <INPUT TYPE="radio" NAME="estado" VALUE="s" <?php if($est=='s'){ echo 'CHECKED'; } ?>> Activo
            <INPUT TYPE="radio" NAME="estado" VALUE="n" <?php if($est=='n'){ echo 'CHECKED'; } ?>> No Activo
             </p>
            <br></td>
           </tr>
         <tr>
           <td><p><?php if(!empty($_SESSION['f_mensaje'])){ echo $_SESSION['f_mensaje']; }else{ echo 'Digite Bien los datos'; } ?></p></td>
           <td><div align="right">
          <?php if(empty($_GET['codigo'])){
                     echo 
'<input type="submit" name="button" class="btn success" id="button" value="Guardar Producto">';
          }else{
                  echo 
'<input type="submit" name="button" class="btn success" id="button" value="Actualizar Producto">';
          }
          
?>
           </div></td>
         </tr>
       </table>
      </form> 
       </div>
</div>
</div>
</body>
</html>
y el otro que es dodne tengo los querys que hacen la actualizacion o la insercion

Código PHP:
<?php
session_start
(); 
// tamaño 40000
include('php_conexion.php');
error_reporting(E_ALL);
$codigo=$_POST['codigo'];
$_SESSION['f_mensaje']="Elija una imagen de tipo *.JPG";

$estado=$_POST['estado'];
if(empty(
$_POST['nom'])){    $nom='Sin Asignar';          }else{    $nom=$_POST['nom'];}
if(empty(
$_POST['des'])){    $des='Sin Descripcion';        }else{    $des=$_POST['des'];}

    
$nameimagen $_FILES['imagen']['name'];
    
$tmpimagen $_FILES['imagen']['tmp_name'];
    
$extimagen pathinfo($nameimagen);
    
$ext = array("png","jpg");
    
$urlnueva "foto/".$codigo.".jpg";
    if(
is_uploaded_file($tmpimagen)){
        
copy($tmpimagen,$urlnueva);
    
    }

$can=mysql_query("SELECT * FROM productos WHERE id=$codigo");
if(
$datos=mysql_fetch_array($can)){
    
$sql="Update productos Set nom='$nom', des='$des', estado='$estado', fondo='$fondo' WHERE id=$codigo";
    
mysql_query($sql);
    
$_SESSION['f_mensaje'] = "Se ha Actualizado Perfectamente";
    
header('location:lista_productos.php');
}else{
    
$sql="INSERT INTO productos (id, nom, des, estado, fondo) VALUES ($codigo,'$nom','$des','$estado', '$fondo')";
    
mysql_query($sql);
    
$_SESSION['f_mensaje'] = "Se ha Guardado Perfectamente";
    
header('location:producto.php');
}

?>
HELPPPPPPPP!!!!!

Muchas gracias
  #2 (permalink)  
Antiguo 20/04/2013, 01:16
Avatar de Triby
Mod on free time
 
Fecha de Ingreso: agosto-2008
Ubicación: $MX->Gto['León'];
Mensajes: 10.106
Antigüedad: 15 años, 8 meses
Puntos: 2237
Respuesta: Undefined variable:XXXX Problema

La asignación que haces a $fondo en el primer script no queda visible para el segundo, porque PHP interpreta cada script desde cero y no conserva los valores al finalizar, sólo necesitas algo como:

$fondo = $_POST['fondo'];
__________________
- León, Guanajuato
- GV-Foto
  #3 (permalink)  
Antiguo 20/04/2013, 12:18
 
Fecha de Ingreso: abril-2013
Mensajes: 34
Antigüedad: 11 años
Puntos: 0
Respuesta: Undefined variable:XXXX Problema

Milll gracias

Me funciono super bien muchas gracias totales...

Etiquetas: formulario, html, mysql, select, sql, undefined
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 15:10.