Ver Mensaje Individual
  #1 (permalink)  
Antiguo 29/03/2015, 09:39
Avatar de sven_uri
sven_uri
 
Fecha de Ingreso: mayo-2011
Mensajes: 109
Antigüedad: 13 años
Puntos: 4
Pregunta UPDATEs vacios

Buenas tardes a todos,

Soy novato con php y hasta ahora me he podido apañar yo solo pero he llegado en un punto que no veo que estoy haciendo mal. Puede que vosotros veáis lo que yo no he conseguido ver aun, ya me diréis.

Problema: Tengo un formulario que a través de POO me hace un update a una tabla. Resulta que realmente el update lo está haciendo pero sustituyendo todos los valores que le paso por formulario como vacíos. De manera que parece que realmente sí que está haciendo el update pero no como debería. No sé si es el orden en que tengo situadas las instrucciones.

Nota: Recupera correctamente los valores del producto que se selecciona. El problema solo esta cuando se hace el update.
Nota 2: No devuelve ningún error.

A mi parecer, creo que en algún momento se pierden los valores, pero no entiendo el por qué.

Gracias por vuestro tiempo : )


Código:
Código PHP:
Ver original
  1. <?php
  2. $db = ASDatabase::getInstance();
  3.  
  4.     // Variable que envio para entrar en el producto pertinente
  5.    
  6.     $idProd= $_POST['form_idProd'];
  7.  
  8. $result = $db->select("SELECT intContador, strTipo FROM `tblcategorias` ORDER BY tblcategorias.strTipo ASC");
  9. $editarProd = $db->select(
  10.              "SELECT * FROM `tblprod` WHERE `intContador` = :id",
  11.               array ("id" => $idProd)
  12.           );
  13.  
  14.  
  15. foreach($editarProd as $InfoProd) {  
  16.     $id= $InfoProd['intContador'];
  17.     $nom = $InfoProd['strProd'];
  18.     $tipus = $InfoProd['idTipo'];
  19.     $url = $InfoProd['strUrl'];
  20.     $fort = $InfoProd['intFuerte'];
  21.     $imatge = $InfoProd['strImagen'];
  22.     $desc = $InfoProd['strDescripcion'];
  23.     $fecha = $InfoProd['fchFecha'];  
  24. }
  25.  
  26.  
  27. include 'templates/menu-izq-admin.php';
  28. ?>
  29.  
  30.               <div class="span9 profile-details-wrapper">
  31.                     <!-- main content here -->  
  32. <!------------------------------------ INICIO FORMULARIO -------------------------------------------->                
  33.                     <form class="form-horizontal" id="form-editar" name="form-editar" action="prod-lista.php" method="post">
  34.                         <fieldset>
  35.                        
  36.                         <!-- Form Name -->
  37.                         <legend><?php echo "EDITAR: "; ?></legend>
  38.                        
  39.                         <!-- INICIO NOMBRE -->
  40.                         <div class="control-group form-group">
  41.                           <label class="control-label col-lg-4" for="nom">
  42.                             <?php echo "Nombre"; ?>
  43.                           </label>
  44.                           <div class="controls col-lg-8">
  45.                             <input id="new_nom" name="new_nom" type="text" placeholder="Introduce el nombre..." class="input-xlarge form-control" value="<?php echo $nom ?>">
  46.                            
  47.                           </div>
  48.                         </div>
  49.                         <!-- FIN NOMBRE -->
  50.                          <!-- INICIO TIPO  -->
  51.                         <div class="control-group form-group">
  52.                           <label class="control-label col-lg-4" for="tipo">
  53.                             <?php echo "Qué es?"; ?>
  54.                           </label>
  55.                           <div class="controls col-lg-8">
  56.                            <select id="new_tipo" name="new_tipo" class="form-control" style="width: 100%;">
  57.                                 <option value="1" <?php if (!(strcmp(1, htmlentities($tipus, ENT_COMPAT, 'utf-8')))) {echo "SELECTED";} ?>>Servicio</option>
  58.                                 <option value="2" <?php if (!(strcmp(2, htmlentities($tipus, ENT_COMPAT, 'utf-8')))) {echo "SELECTED";} ?>>Producto</option>
  59.                                 <option value="3" <?php if (!(strcmp(3, htmlentities($tipus, ENT_COMPAT, 'utf-8')))) {echo "SELECTED";} ?>>Nada</option>
  60.                            </select>
  61.                           </div>
  62.                         </div>
  63.                         <!-- FIN TIPO  -->
  64.                         <!-- URL YOUTUBE -->
  65.                         <div class="control-group form-group">
  66.                           <label class="control-label col-lg-4" for="url">
  67.                             <?php echo "URL de Youtube"; ?>
  68.                           </label>
  69.                           <div class="controls col-lg-8">
  70.                             <input id="new_url" name="new_url" type="text" placeholder="Introduce la url del vídeo" class="input-xlarge form-control" value="<?php echo $url ?>">
  71.                            
  72.                           </div>
  73.                         </div>
  74.                         <!-- FIN URL YOUTUBE -->
  75.                         <!-- INICIO FUERTE-->
  76.                         <div class="control-group form-group">
  77.                           <label class="control-label col-lg-4" for="fuerte">
  78.                             <?php echo "Fuerte"; ?>
  79.                           </label>
  80.                           <div class="controls col-lg-8">
  81.                            <select id="new_fuerte" name="new_fuerte" class="form-control" style="width: 100%;">
  82.                                 <option value="0" <?php if (!(strcmp(0, htmlentities($fort, ENT_COMPAT, 'utf-8')))) {echo "SELECTED";} ?>>0</option>
  83.                                 <option value="1" <?php if (!(strcmp(1, htmlentities($fort, ENT_COMPAT, 'utf-8')))) {echo "SELECTED";} ?>>1</option>
  84.                                 <option value="2" <?php if (!(strcmp(2, htmlentities($fort, ENT_COMPAT, 'utf-8')))) {echo "SELECTED";} ?>>2</option>                 
  85.                            </select>
  86.                           </div>
  87.                         </div>
  88.                         <!-- FIN FUERTE-->
  89.                         <!-- INICIO IMAGEN -->                      
  90.                         <div class="control-group form-group">
  91.                           <label class="control-label col-lg-4" for="imagen">
  92.                             <?php echo "Imagen"; ?>
  93.                           </label>
  94.                           <div class="controls col-lg-8">
  95.                             <input id="new_imagen" name="new_imagen" type="text" placeholder="Selecciona una imagen" class="input-xlarge form-control" value="<?php echo $imatge ?>">  
  96.                           </div>
  97.                         </div>
  98.                         <!-- FIN IMAGEN -->
  99.                         <!-- DESCRIPCIÓN -->
  100.                         <div class="control-group form-group">
  101.                           <label class="control-label col-lg-4" for="desc">
  102.                             <?php echo "Descripción"; ?>
  103.                           </label>
  104.                           <div class="controls col-lg-8">
  105.                           <textarea id="new_desc" name="new_desc"><?php echo $desc ?></textarea>                          
  106.                           </div>
  107.                         </div>
  108.                         <!-- FIN DESCRIPCIÓN -->
  109.                         <!-- Button -->
  110.                         <div class="control-group form-group">
  111.                           <label class="control-label col-lg-4" for="subir"></label>
  112.                           <div class="controls col-lg-8">
  113.                             <button id="subir" name="subir" class="btn btn-primary" type="submit">
  114.                               <?php echo "Actualizar"; ?>
  115.                             </button>
  116.                             <a href="prod-lista.php">
  117.                             <button id="atras" name="atras" class="btn btn-primary" type="button" style="background-color:red">
  118.                               <?php echo "Volver atrás"; ?>
  119.                             </button>
  120.                           </a>                          </div>
  121.                         </div>
  122.                         <input type="hidden" name="MM_update" value="form-editar">
  123.                         </fieldset>
  124.                     </form>
  125. <!------------------------------------ FIN FORMULARIO  -------------------------------------------->        
  126. <?php
  127. if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form-editar"))
  128. {
  129. $new_nom = $_POST['new_nom'];
  130. $new_tipo = $_POST['new_tipo'];
  131. $new_url = $_POST['new_url'];
  132. $new_fuerte = $_POST['new_fuerte'];
  133. $new_imagen = $_POST['new_imagen'];
  134. $new_descripcion = $_POST['new_desc'];
  135.  
  136.  
  137. $db->update(
  138.      'tblprod',
  139.      array ( "strNom" => $new_nom,
  140.              "idTipo" => $new_tipo,
  141.              "strUrl" => $new_url,
  142.              "intFuerte" => $new_fuerte,
  143.              "strImagen" => $new_imagen,
  144.              "strDescripcion" => $new_descripcion ),
  145.      "intContador = :id",
  146.      array ("id" => $idProd)
  147. );
  148. }
  149. ?>