Ver Mensaje Individual
  #2 (permalink)  
Antiguo 05/01/2012, 05:04
oliverarthurnardi
 
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>