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