Foros del Web » Programando para Internet » PHP »

problema registro,lista en php

Estas en el tema de problema registro,lista en php en el foro de PHP en Foros del Web. Hola buenas chicos de nuevo!! Me acabo de encontrar con otro problemita con la pagina que estoy haciendo. aqui os dejo unas imagenes de lo ...
  #1 (permalink)  
Antiguo 05/01/2012, 05:01
 
Fecha de Ingreso: noviembre-2010
Ubicación: aun no se donde vivir
Mensajes: 112
Antigüedad: 13 años, 5 meses
Puntos: 3
problema registro,lista en php

Hola buenas chicos de nuevo!!

Me acabo de encontrar con otro problemita con la pagina que estoy haciendo.

aqui os dejo unas imagenes de lo que me esta pasando:

IMG 1:
[IMG][/IMG]

IMG 2:

[IMG] Uploaded with ImageShack.us[/IMG]

El problema esta que cuando inserto una categoria nueva en la lista de categoria me aparece a la derecha y no debajo de la otra categoria y en el formulario de añadir nuevo producto me aparece repetida la categoria.
  #2 (permalink)  
Antiguo 05/01/2012, 05:04
 
Fecha de Ingreso: noviembre-2010
Ubicación: aun no se donde vivir
Mensajes: 112
Antigüedad: 13 años, 5 meses
Puntos: 3
Respuesta: problema registro,lista en php

codigo de lista de categoria

Código PHP:
Ver original
  1. <?php require_once('../Connections/evatienda.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_evatienda, $evatienda);
  35. $query_category = "SELECT * FROM categoria ORDER BY categoria.`description` ASC";
  36. $category = mysql_query($query_category, $evatienda) or die(mysql_error());
  37. $row_category = mysql_fetch_assoc($category);
  38. $totalRows_category = mysql_num_rows($category);
  39. ?>
  40. <div class="content">
  41.     <h2>Lista de categor&iacute;as    </h2>
  42.     <table width="100%" border="0" align="center" cellpadding="6" cellspacing="6">
  43.       <tr>
  44.         <td width="48%" bgcolor="#FFFFFF">Nombre de la categoria</td>
  45.         <td width="52%" bgcolor="#FFFFFF">Acciones</td>
  46.       </tr>
  47.       <tr>
  48.         <?php do { ?>
  49.           <td><?php echo $row_category['description']; ?></td>
  50.           <td>Editar - Eliminar</td>
  51.           <?php } while ($row_category = mysql_fetch_assoc($category)); ?>
  52.       </tr>
  53.     </table>

Codigo de añadir categoria

Código PHP:
Ver original
  1. <?php require_once('../Connections/evatienda.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. $editFormAction = $_SERVER['PHP_SELF'];
  35. if (isset($_SERVER['QUERY_STRING'])) {
  36.   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  37. }
  38.  
  39. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  40.   $insertSQL = sprintf("INSERT INTO categoria (`description`) VALUES (%s)",
  41.                        GetSQLValueString($_POST['description'], "text"));
  42.  
  43.   mysql_select_db($database_evatienda, $evatienda);
  44.   $Result1 = mysql_query($insertSQL, $evatienda) or die(mysql_error());
  45.  
  46.   $insertGoTo = "categorias_listas.php";
  47.   if (isset($_SERVER['QUERY_STRING'])) {
  48.     $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
  49.     $insertGoTo .= $_SERVER['QUERY_STRING'];
  50.   }
  51.   header(sprintf("Location: %s", $insertGoTo));
  52. }
  53. ?>
  54. <div class="content">
  55.     <h2>A&ntilde;adir categoras</h2>
  56.     <p>&nbsp;</p>
  57.     <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
  58.       <table align="center">
  59.         <tr valign="baseline">
  60.           <td nowrap="nowrap" align="right">Descripci&oacute;n:</td>
  61.           <td><input type="text" name="description" value="" size="32" /></td>
  62.         </tr>
  63.         <tr valign="baseline">
  64.           <td nowrap="nowrap" align="right">&nbsp;</td>
  65.           <td><input type="submit" value="Insertar categoria" /></td>
  66.         </tr>
  67.       </table>
  68.       <input type="hidden" name="MM_insert" value="form1" />
  69.     </form>
  #3 (permalink)  
Antiguo 05/01/2012, 05:06
 
Fecha de Ingreso: noviembre-2010
Ubicación: aun no se donde vivir
Mensajes: 112
Antigüedad: 13 años, 5 meses
Puntos: 3
Respuesta: problema registro,lista en php

codigo de añadir producto
Código PHP:
Ver original
  1. <?php require_once('../Connections/evatienda.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. $editFormAction = $_SERVER['PHP_SELF'];
  35. if (isset($_SERVER['QUERY_STRING'])) {
  36.   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  37. }
  38.  
  39. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  40.   $insertSQL = sprintf("INSERT INTO producto (name_product, price_product, `state`, category, `size`, photo, `description`) VALUES (%s, %s, %s, %s, %s, %s, %s)",
  41.                        GetSQLValueString($_POST['name_product'], "text"),
  42.                        GetSQLValueString($_POST['price_product'], "double"),
  43.                        GetSQLValueString($_POST['state'], "int"),
  44.                        GetSQLValueString($_POST['category'], "int"),
  45.                        GetSQLValueString($_POST['size'], "text"),
  46.                        GetSQLValueString($_POST['photo'], "text"),
  47.                        GetSQLValueString($_POST['description'], "text"));
  48.  
  49.   mysql_select_db($database_evatienda, $evatienda);
  50.   $Result1 = mysql_query($insertSQL, $evatienda) or die(mysql_error());
  51.  
  52.   $insertGoTo = "productos_listas.php";
  53.   if (isset($_SERVER['QUERY_STRING'])) {
  54.     $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
  55.     $insertGoTo .= $_SERVER['QUERY_STRING'];
  56.   }
  57.   header(sprintf("Location: %s", $insertGoTo));
  58. }
  59.  
  60. mysql_select_db($database_evatienda, $evatienda);
  61. $query_ConsultaCategoria = "SELECT * FROM categoria ORDER BY categoria.`description` ASC";
  62. $ConsultaCategoria = mysql_query($query_ConsultaCategoria, $evatienda) or die(mysql_error());
  63. $row_ConsultaCategoria = mysql_fetch_assoc($ConsultaCategoria);
  64. $totalRows_ConsultaCategoria = mysql_num_rows($ConsultaCategoria);
  65. ?>
  66. <div class="content">
  67.     <h2>A&ntilde;adir producto</h2>
  68.     <p>&nbsp;</p>
  69.     <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
  70.       <table align="center">
  71.         <tr valign="baseline">
  72.           <td nowrap="nowrap" align="right">Nombre del producto:</td>
  73.           <td><input type="text" name="name_product" value="" size="32" /></td>
  74.         </tr>
  75.         <tr valign="baseline">
  76.           <td nowrap="nowrap" align="right">Precio:</td>
  77.           <td><input type="text" name="price_product" value="" size="32" /></td>
  78.         </tr>
  79.         <tr valign="baseline">
  80.           <td nowrap="nowrap" align="right">Estado:</td>
  81.           <td><select name="state">
  82.             <option value="1" <?php if (!(strcmp(1, ""))) {echo "SELECTED";} ?>>Activo</option>
  83.             <option value="0" <?php if (!(strcmp(0, ""))) {echo "SELECTED";} ?>>Inactivo</option>
  84.           </select></td>
  85.         </tr>
  86.         <tr valign="baseline">
  87.           <td nowrap="nowrap" align="right">Categoria:</td>
  88.           <td><label for=""></label>
  89.             <select name="categoria" id="categoria">
  90.             <?php
  91. do {
  92. ?>
  93.              <option value=" <?php echo $row_ConsultaCategoria['idcategory']?>" selected="selected"><?php echo
  94. $row_ConsultaCategoria['description']?></option>
  95.              <?php
  96. } while ($Categoria = mysql_fetch_assoc($ConsultaCategoria));
  97.   $rows = mysql_num_rows($ConsultaCategoria);
  98.   if($rows > 0) {
  99.       mysql_data_seek($ConsultaCategoria, 0);
  100.       $Categoria = mysql_fetch_assoc($ConsultaCategoria);
  101.   }
  102. ?>
  103.           </select></td>
  104.         </tr>
  105.         <tr valign="baseline">
  106.           <td nowrap="nowrap" align="right">Size:</td>
  107.           <td><select name="size">
  108.             <option value="S" <?php if (!(strcmp("S", ""))) {echo "SELECTED";} ?>>S</option>
  109.             <option value="M" <?php if (!(strcmp("M", ""))) {echo "SELECTED";} ?>>M</option>
  110.             <option value="L" <?php if (!(strcmp("L", ""))) {echo "SELECTED";} ?>>L</option>
  111.             <option value="XL" <?php if (!(strcmp("XL", ""))) {echo "SELECTED";} ?>>XL</option>
  112.             <option value="XXL" <?php if (!(strcmp("XXL", ""))) {echo "SELECTED";} ?>>XXL</option>
  113.           </select></td>
  114.         </tr>
  115.         <tr valign="baseline">
  116.           <td nowrap="nowrap" align="right">Photo:</td>
  117.           <td><input type="file" name="photo" value="" size="32" /></td>
  118.         </tr>
  119.         <tr valign="baseline">
  120.           <td nowrap="nowrap" align="right">Descripción:</td>
  121.           <td><input type="text" name="description" value="" size="32" /></td>
  122.         </tr>
  123.         <tr valign="baseline">
  124.           <td nowrap="nowrap" align="right">&nbsp;</td>
  125.           <td><input type="submit" value="Insertar registro" /></td>
  126.         </tr>
  127.       </table>
  128.       <input type="hidden" name="MM_insert" value="form1" />
  129.     </form>
  #4 (permalink)  
Antiguo 05/01/2012, 06:16
Avatar de Eleazan  
Fecha de Ingreso: abril-2008
Ubicación: Ibiza
Mensajes: 1.879
Antigüedad: 16 años
Puntos: 326
Respuesta: problema registro,lista en php

Veamos,

El "Listado de categorias", que se te va "al lao" y "no abajo"

Tienes este código:
Código PHP:
<h2>Lista de categor&iacute;as    </h2>
    <table width="100%" border="0" align="center" cellpadding="6" cellspacing="6">
      <tr>
        <td width="48%" bgcolor="#FFFFFF">Nombre de la categoria</td>
        <td width="52%" bgcolor="#FFFFFF">Acciones</td>
      </tr>
      <tr>
        <?php do { ?>
          <td><?php echo $row_category['description']; ?></td>
          <td>Editar - Eliminar</td>
          <?php } while ($row_category mysql_fetch_assoc($category)); ?>
      </tr>
    </table>
Si te fijas, estás haciendo "dos celdas" por cada categoria... sin cambiar el "row" (fila). Deberías tener algo así
Código PHP:
<h2>Lista de categor&iacute;as    </h2>
    <table width="100%" border="0" align="center" cellpadding="6" cellspacing="6">
      <tr>
        <td width="48%" bgcolor="#FFFFFF">Nombre de la categoria</td>
        <td width="52%" bgcolor="#FFFFFF">Acciones</td>
      </tr>
      
        <?php do { ?>
          <tr><td><?php echo $row_category['description']; ?></td>
          <td>Editar - Eliminar</td></tr>
          <?php } while ($row_category mysql_fetch_assoc($category)); ?>
      
    </table>
Que, básicamente, lo que he hecho ha sido cambiar el <tr> y </tr>, para ponerlos dentro del do ... while.
__________________
>> Eleazan's Source
>> @Eleazan
  #5 (permalink)  
Antiguo 05/01/2012, 06:18
Avatar de Eleazan  
Fecha de Ingreso: abril-2008
Ubicación: Ibiza
Mensajes: 1.879
Antigüedad: 16 años
Puntos: 326
Respuesta: problema registro,lista en php

Y el otro problema, creo que está aqui:

Código PHP:
do {
?>
             <option value=" <?php echo $row_ConsultaCategoria['idcategory']?>" selected="selected"><?php echo 
$row_ConsultaCategoria['description']?></option>
             <?php 
} while ($Categoria mysql_fetch_assoc($ConsultaCategoria));
Ese es el trozo de código que usas para generar los option del select. Veamos... ¿wtf is $row_ConsultaCategoria? ¡No cambia de valor durante el do..while! Creo q deberías usar $Categoria en vez del otro ;)
__________________
>> Eleazan's Source
>> @Eleazan
  #6 (permalink)  
Antiguo 05/01/2012, 08:11
 
Fecha de Ingreso: noviembre-2010
Ubicación: aun no se donde vivir
Mensajes: 112
Antigüedad: 13 años, 5 meses
Puntos: 3
Respuesta: problema registro,lista en php

Cita:
Iniciado por Eleazan Ver Mensaje
Y el otro problema, creo que está aqui:

Código PHP:
do {
?>
             <option value=" <?php echo $row_ConsultaCategoria['idcategory']?>" selected="selected"><?php echo 
$row_ConsultaCategoria['description']?></option>
             <?php 
} while ($Categoria mysql_fetch_assoc($ConsultaCategoria));
Ese es el trozo de código que usas para generar los option del select. Veamos... ¿wtf is $row_ConsultaCategoria? ¡No cambia de valor durante el do..while! Creo q deberías usar $Categoria en vez del otro ;)
Hola buenas Eleazaann lo de la lista de categoria ya lo solucione ... no me habia dado cuenta lo de las celdas ;) y encuanto a los del $row_CosultaCategoria si lo cambio a $categoria me da error .......a ver yo que esto del php me pierdo un poco tadavia me hace falta un poco :(

Un saludo
  #7 (permalink)  
Antiguo 05/01/2012, 08:15
Avatar de Eleazan  
Fecha de Ingreso: abril-2008
Ubicación: Ibiza
Mensajes: 1.879
Antigüedad: 16 años
Puntos: 326
Respuesta: problema registro,lista en php

Vale, cambia
Código PHP:
} while ($Categoria mysql_fetch_assoc($ConsultaCategoria)); 
por
Código PHP:
} while ($row_ConsultaCategoria mysql_fetch_assoc($ConsultaCategoria)); 
Así debería funcionarte ;)
__________________
>> Eleazan's Source
>> @Eleazan
  #8 (permalink)  
Antiguo 05/01/2012, 08:34
 
Fecha de Ingreso: noviembre-2010
Ubicación: aun no se donde vivir
Mensajes: 112
Antigüedad: 13 años, 5 meses
Puntos: 3
Respuesta: problema registro,lista en php

Cita:
Iniciado por Eleazan Ver Mensaje
Vale, cambia
Código PHP:
} while ($Categoria mysql_fetch_assoc($ConsultaCategoria)); 
por
Código PHP:
} while ($row_ConsultaCategoria mysql_fetch_assoc($ConsultaCategoria)); 
Así debería funcionarte ;)
Muchas gracias Eleazan!!!!

Bueno funciona perfecto... ahora voy a ir avanzando un poco mas porque estaba parado por esto.. espero que no me salgan mas errores aunque por un lado es bueno, asi aprendo mas ;)

Muchas Gracias

Etiquetas: formulario, imagenes
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 23:51.