Ver Mensaje Individual
  #9 (permalink)  
Antiguo 20/10/2012, 09:44
xeic
 
Fecha de Ingreso: octubre-2012
Mensajes: 7
Antigüedad: 11 años, 6 meses
Puntos: 0
Respuesta: Actualizar registro desde menús desplegables dependientes

Y esto el editor de productos (sorry por ponerlo mal al principio)

Código PHP:
Ver original
  1. <?php require_once('../Connections/conexionproductos.php'); ?>
  2. <script>
  3.  
  4. function requerir(){
  5.     try{
  6.     req=new XMLHttpRequest();
  7.     }catch(err1){
  8.         try{
  9.         req=new ActiveXObject("Microsoft.XMLHTTP");
  10.         }catch(err2){
  11.             try{
  12.             req=new ActiveXObject("Msxml2.XMLHTTP");
  13.             }catch(err3){
  14.             req= false;
  15.             }
  16.         }
  17.     }
  18. return req;
  19. }
  20.  
  21. var peticion=requerir();
  22. function llamarAjaxGETpro(){
  23. var aleatorio=parseInt(Math.random()*999999999);
  24. valor=document.getElementById("catH").value;
  25. var url="categoriaH1.php?valor="+valor+"&r="+aleatorio;
  26. peticion.open("GET",url,true);
  27. peticion.onreadystatechange =respuestaAjaxpro;
  28. peticion.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  29. peticion.send(null);
  30. }
  31.  
  32. function llamarAjaxGETdis(){
  33. var aleatorio=parseInt(Math.random()*999999999);
  34. valor=document.getElementById("categoriaH1").value;
  35. var url="categoriaH2.php?valor="+valor+"&r="+aleatorio;
  36. peticion.open("GET",url,true);
  37. peticion.onreadystatechange =respuestaAjaxdis;
  38. peticion.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  39. peticion.send(null);
  40. }
  41.  
  42. function respuestaAjaxpro(){
  43.  
  44.     if(peticion.readyState==4){
  45.         if(peticion.status==200){
  46.         //alert(peticion.responseText);
  47.         document.getElementById("catH1").innerHTML=peticion.responseText;
  48.         }else{
  49.         alert("ha ocurrido un error"+peticion.statusText);
  50.         }
  51.     }
  52. }
  53. function respuestaAjaxdis(){
  54.  
  55.     if(peticion.readyState==4){
  56.         if(peticion.status==200){
  57.         //alert(peticion.responseText);
  58.         document.getElementById("catH2").innerHTML=peticion.responseText;
  59.         }else{
  60.         alert("ha ocurrido un error"+peticion.statusText);
  61.         }
  62.     }
  63. }
  64.  
  65. </script>
  66.  
  67. <?php
  68. if (!function_exists("GetSQLValueString")) {
  69. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  70. {
  71.   if (PHP_VERSION < 6) {
  72.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  73.   }
  74.  
  75.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  76.  
  77.   switch ($theType) {
  78.     case "text":
  79.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  80.       break;    
  81.     case "long":
  82.     case "int":
  83.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  84.       break;
  85.     case "double":
  86.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  87.       break;
  88.     case "date":
  89.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  90.       break;
  91.     case "defined":
  92.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  93.       break;
  94.   }
  95.   return $theValue;
  96. }
  97. }
  98.  
  99. $editFormAction = $_SERVER['PHP_SELF'];
  100. if (isset($_SERVER['QUERY_STRING'])) {
  101.   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  102. }
  103.  
  104. if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  105.   $updateSQL = sprintf("UPDATE tblproducto SET strProducto=%s, strSEO=%s, dblPrecio=%s, intEstado=%s, intCategoriaH=%s, intCategoriaH1=%s, intCategoriaH2=%s, strImagen=%s, strDescripcion=%s WHERE idProductos=%s",
  106.                        GetSQLValueString($_POST['strProducto'], "text"),
  107.                        GetSQLValueString($_POST['strSEO'], "text"),
  108.                        GetSQLValueString($_POST['dblPrecio'], "double"),
  109.                        GetSQLValueString($_POST['intEstado'], "int"),
  110.                        GetSQLValueString($_POST['intCategoriaH'], "text"),
  111.                        GetSQLValueString($_POST['intCategoriaH1'], "text"),
  112.                        GetSQLValueString($_POST['intCategoriaH2'], "text"),
  113.                        GetSQLValueString($_POST['strImagen'], "text"),
  114.                        GetSQLValueString($_POST['strDescripcion'], "text"),
  115.                        GetSQLValueString($_POST['idProductos'], "int"));
  116.  
  117.   mysql_select_db($database_conexionproductos, $conexionproductos);
  118.   $Result1 = mysql_query($updateSQL, $conexionproductos) or die(mysql_error());
  119.  
  120.   $updateGoTo = "productos_lista.php";
  121.   if (isset($_SERVER['QUERY_STRING'])) {
  122.     $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
  123.     $updateGoTo .= $_SERVER['QUERY_STRING'];
  124.   }
  125.   header(sprintf("Location: %s", $updateGoTo));
  126. }
  127.  
  128. $colname_consulta_productos = "0";
  129. if (isset($_GET['recordID'])) {
  130.   $colname_consulta_productos = $_GET['recordID'];
  131. }
  132. mysql_select_db($database_conexionproductos, $conexionproductos);
  133. $query_consulta_productos = sprintf("SELECT * FROM tblproducto WHERE idProductos = %s", GetSQLValueString($colname_consulta_productos, "int"));
  134. $consulta_productos = mysql_query($query_consulta_productos, $conexionproductos) or die(mysql_error());
  135. $row_consulta_productos = mysql_fetch_assoc($consulta_productos);
  136. $totalRows_consulta_productos = mysql_num_rows($consulta_productos);
  137.  
  138. mysql_select_db($database_conexionproductos, $conexionproductos);
  139. $query_consultaH = "SELECT * FROM tblcategoriah ORDER BY tblcategoriah.strSiglas ASC";
  140. $consultaH = mysql_query($query_consultaH, $conexionproductos) or die(mysql_error());
  141. $row_consultaH = mysql_fetch_assoc($consultaH);
  142. $totalRows_consultaH = mysql_num_rows($consultaH);
  143. ?>
  144. (...)
  145.  
  146. <body>
  147.  
  148. <div class="container">
  149.   <div class="header">
  150.     <!-- end .header -->
  151.     <img src="http://www.forosdelweb.com/f18/imatges/img05.jpg" width="961" height="300" /></div>
  152.   <div class="sidebar1">
  153.     <?php include("../includes/cabeceraadmin.php");
  154. ?>
  155.     <!-- end .sidebar1 -->
  156.   </div>
  157.   <div class="content"><!-- InstanceBeginEditable name="Contenido" -->
  158.    
  159.     <h1>Editar producto</h1>
  160.     <p>&nbsp;</p>
  161.     <p>&nbsp;</p>
  162.     <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
  163.       <table align="center">
  164.         <tr valign="baseline">
  165.           <td nowrap="nowrap" align="right">Producto:</td>
  166.           <td><input type="text" name="strProducto" value="<?php echo htmlentities($row_consulta_productos['strProducto'], ENT_COMPAT, 'iso-8859-1'); ?>" size="32" /></td>
  167.         </tr>
  168.         <tr valign="baseline">
  169.           <td nowrap="nowrap" align="right">SEO:</td>
  170.           <td><input type="text" name="strSEO" value="<?php echo htmlentities($row_consulta_productos['strSEO'], ENT_COMPAT, 'iso-8859-1'); ?>" size="32" /></td>
  171.         </tr>
  172.         <tr valign="baseline">
  173.           <td nowrap="nowrap" align="right">Precio:</td>
  174.           <td><input type="text" name="dblPrecio" value="<?php echo htmlentities($row_consulta_productos['dblPrecio'], ENT_COMPAT, 'iso-8859-1'); ?>" size="32" /></td>
  175.         </tr>
  176.         <tr valign="baseline">
  177.           <td nowrap="nowrap" align="right">Estado:</td>
  178.           <td><select name="intEstado">
  179.             <option value="1" <?php if (!(strcmp(1, htmlentities($row_consulta_productos['intEstado'], ENT_COMPAT, 'iso-8859-1')))) {echo "SELECTED";} ?>>Activo</option>
  180.             <option value="0" <?php if (!(strcmp(0, htmlentities($row_consulta_productos['intEstado'], ENT_COMPAT, 'iso-8859-1')))) {echo "SELECTED";} ?>>Inactivo</option>
  181.           </select></td>
  182.         </tr>
  183.         <tr valign="baseline">
  184.           <td nowrap="nowrap" align="right">Categoría H:</td>
  185.           <td><div id="dep">
  186.           <select name="catH" id="catH" onChange="llamarAjaxGETpro()" >
  187.           <option> Seleccione Categoría H </option>
  188.             <?php
  189. do {  
  190. ?>
  191.             <option value="<?php echo $row_consultaH['strSiglas']?>" <?php if (!(strcmp($row_consultaH[ 'strSiglas'], htmlentities($row_consulta_productos['intCategoriaH'], ENT_COMPAT, 'iso-8859-1')))) {echo "SELECTED";} ?>><?php echo $row_consultaH['strDescripcion']?></option>
  192.             <?php
  193. } while ($row_consultaH = mysql_fetch_assoc($consultaH));
  194. ?>
  195.           </select></div></td>
  196.         </tr>
  197.         <tr> </tr>
  198.         <tr valign="baseline">
  199.           <td nowrap="nowrap" align="right">Categoría H1:</td>
  200.           <td> <div id="catH1">
  201.           <select disabled="disabled">
  202.                 <option> Seleccione primero Categoría H </option>
  203.           </select></div></td>
  204.         </tr>
  205.         <tr> </tr>
  206.         <tr valign="baseline">
  207.           <td nowrap="nowrap" align="right">Categoría H2:</td>
  208.           <td><div id="catH2">
  209.           <select disabled="disabled">
  210.  <option> Seleccione primero Categoría H1</option>
  211.           </select></div></td>
  212.         </tr>
  213.         <tr> </tr>
  214.         <tr valign="baseline">
  215.           <td nowrap="nowrap" align="right">Imagen:</td>
  216.           <td><input type="text" name="strImagen" value="<?php echo htmlentities($row_consulta_productos['strImagen'], ENT_COMPAT, 'iso-8859-1'); ?>" size="32" /></td>
  217.         </tr>
  218.         <tr valign="baseline">
  219.           <td nowrap="nowrap" align="right">Descripción:</td>
  220.           <td><input type="text" name="strDescripcion" value="<?php echo htmlentities($row_consulta_productos['strDescripcion'], ENT_COMPAT, 'iso-8859-1'); ?>" size="32" /></td>
  221.         </tr>
  222.         <tr valign="baseline">
  223.           <td nowrap="nowrap" align="right">&nbsp;</td>
  224.           <td><input type="submit" value="Actualizar registro" /></td>
  225.         </tr>
  226.       </table>
  227.       <input type="hidden" name="MM_update" value="form1" />
  228.       <input type="hidden" name="idProductos" value="<?php echo $row_consulta_productos['idProductos']; ?>" />
  229.     </form>
  230.     <p>&nbsp;</p>
  231. <p>&nbsp;</p>
  232. <p>&nbsp;</p>
  233. <p>&nbsp;</p>
  234. <p>&nbsp;</p>
  235. <p>&nbsp;</p>
  236.   <!-- InstanceEndEditable -->
  237.    
  238.     <!-- end .content --></div>
  239.   <div class="footer">
  240.     <p>Administración MAGALDISOUND</p>
  241.     <!-- end .footer --></div>
  242.   <!-- end .container --></div>
  243. </body>
  244. <!-- InstanceEnd --></html>
  245. <?php
  246. mysql_free_result($consulta_productos);
  247.  
  248. mysql_free_result($consultaH);
  249. ?>