Ver Mensaje Individual
  #4 (permalink)  
Antiguo 10/04/2016, 21:47
Avatar de aviweb2015
aviweb2015
 
Fecha de Ingreso: abril-2016
Ubicación: venezuela
Mensajes: 215
Antigüedad: 8 años, 1 mes
Puntos: 1
Respuesta: for no deja ingresar dos prudoctos

la otra parte

Código PHP:
Ver original
  1. <?php
  2. if (isset($_GET['id']))
  3. $id = $_GET['id'];
  4. else
  5. $id = 1;
  6. if (isset($_GET['action']))
  7. $action = $_GET['action'];
  8. else
  9. $action = "empty";
  10.  
  11. switch($action){
  12.      
  13. case "add":
  14. if(isset($_SESSION['carro'][$id]))
  15. $_SESSION['carro'][$id]++;
  16. else
  17. $_SESSION['carro'][$id]=1;
  18. break;
  19.        
  20. case "remove":
  21. if(isset($_SESSION['carro'][$id]))
  22.           {
  23.             $_SESSION['carro'][$id]--;
  24.             if($_SESSION['carro'][$id]==0)
  25.               unset($_SESSION['carro'][$id]);
  26.           }
  27.          
  28.         break;
  29.         case "removeProd":
  30.           if(isset($_SESSION['carro'][$id])){
  31.             unset($_SESSION['carro'][$id]);
  32.           }
  33.         break;
  34.        
  35.         case "mostrar":
  36.           if(isset($_SESSION['carro'][$id])){
  37.             continue;
  38.           }
  39.         break;
  40.        
  41.         case "empty":
  42.           unset($_SESSION['carro']);
  43.        
  44.         break;
  45.            
  46.        
  47.       }
  48.  
  49.      
  50. if(isset($_SESSION['carro'])){
  51. echo "<form action='carro.php' method='POST'>";
  52. echo "<table class=''>";
  53. $totalcoste = 0;//Inicializamos el contador de productos seleccionados.
  54. $xTotal = 0;
  55.        
  56. echo "<tr>";
  57. echo "<td>Producto</td>";
  58. echo "<td>Cantidad</td>";
  59. echo "<td>Acciones</td>";
  60. echo "<td colspan=2 align=right >&nbsp;&nbsp;&nbsp;&nbsp;SubTotal</td>";
  61. echo "</tr>";
  62. echo "<tr><td colspan=5><hr></td></tr>";
  63.  
  64. foreach($_SESSION['carro'] as $id => $x){
  65. $resultado = mysql_query("SELECT id,descripcion,precio FROM productos WHERE id=$id");
  66. $mifila = mysql_fetch_array($resultado);
  67. $id = $mifila['id'];
  68. $descripcion = $mifila['descripcion'];
  69. //acortamos el nombre del producto a 40 caracteres
  70. $descripcion = substr($descripcion,0,40);
  71. $precio = $mifila['precio'];
  72. //Coste por artículo según la cantidad elegida
  73. $coste = $precio * $x;
  74. //Coste total del carro
  75. $totalcoste = $totalcoste + $coste;
  76. //Contador del total de productos añadidos al carro
  77. $xTotal = $xTotal + $x;
  78.          
  79. echo "<input type='hidden' name=idproductos value='$descripcion'>";
  80.  
  81.  
  82. echo "<tr>";
  83. echo "<td align='left'>$descripcion</td>";
  84. echo "<td align='center'>$x<input type='hidden' name=chk_group3[] value='$x'></td>";
  85.          
  86. echo "<td align='left'>";
  87. echo "<a href='carro.php?id=". $id ."&action=add'><img src='img/aumentar.png' style='padding:0 0px 0 5px;' alt='Aumentar cantidad' /></a>";
  88. echo "<a href='carro.php?id=". $id ."&action=remove'><img src='img/restar.png' alt='Reducir cantidad' /></a>";
  89. echo "<a href='carro.php?id=". $id ."&action=removeProd'><img src='img/eliminar.png' alt='Reducir cantidad' /></a></td>";
  90.          
  91. echo "<td align='right'>  </td>";
  92. echo "<td align='right' style='margin-left:10px'>$coste Bsf
  93. <input type='hidden' name=chk_group2[] value='$coste'>";
  94. echo "</tr>";
  95.  
  96. }
  97.         echo "<tr><td colspan='5'><hr></td></tr>";
  98.         echo "<tr>";
  99.         echo "</table>";
  100.  
  101. echo "<table>";
  102. echo "<td align='right'
  103. colspan='4'><b>
  104. <h4 class='blue-text text-darken-2
  105. right CONDENSED LIGHT5'>Total&nbsp;=&nbsp;$totalcoste&nbsp;Bsf</h4></b></td>
  106. <input type='hidden' name=costetotal value='$totalcoste'>";
  107. echo "</tr>";
  108. echo "</table>";?>
  109. <!-- final de la tabla-->
  110. </div><!-- fin colunna izquiereda -->
  111.  
  112.  
  113.  
  114. <div class="col s12 m8 l5"> <!-- colunna derecha -->
  115. <!-- fecha y numero de factura-->
  116. <div class='input-field col s12 m4'><p class='blue-text text-darken-2'>Fecha:</p>
  117. <input type="text" name="fecha" value="<?php echo date("d/m/Y"); ?>"
  118. readonly="true"/>
  119. </div>
  120. <div class='input-field col s12 m4'><p class='blue-text text-darken-2'>N° de Fact.</p>
  121. <input type="text" name='idfactura' readonly='readonly' value="
  122. <?php
  123. include("conexion.php");
  124. $res=mysql_query("select * from factura");
  125. if($campo=mysql_fetch_array($res))
  126. {
  127. $codigo=mysql_num_rows($res)+1;
  128. echo $codigo=$codigo;
  129. }
  130. if(mysql_num_rows($res)==0)
  131. echo $codigo='1' ;
  132. ?>" >
  133. </div>
  134. <div class='input-field col s12 m4'><p class='blue-text text-darken-2'>Personas</p>
  135. <input id="icon_prefix" type="text" name="personas" autocomplete="off"
  136. title="Se Necesita el numero de Personas Asistir" >
  137. </div>
  138. <div class='input-field col s12 m4'><p class='blue-text text-darken-2'>Tipo de Organización.</p>
  139. <select select name="evento" title="Disculpa, seleccione el Tipo de Organizacion!" required/>
  140. <option value=""  disabled selected>Seleccione</option>
  141. <?php
  142. include('conexion.php');
  143. $result = mysql_query("SELECT * FROM evento");
  144. while ($row=mysql_fetch_array($result)) {
  145. ?>
  146. <option value="<?php echo $row['evento'];?>">
  147. <?php echo $row['evento'];?></option>
  148. <?php
  149. }
  150. mysql_close($link);
  151. ?>
  152. </select>
  153. </div>
  154.  
  155. <div class='input-field col s12 m4'><p class='blue-text text-darken-2'>Lugar del Evento</p>
  156. <input id="icon_prefix" type="text" name="lugar_evento" autocomplete="off"
  157. title="Se Necesita el lugar" >
  158. </div>
  159.  
  160.  
  161. <div class='input-field col s12 m4'><p class='blue-text text-darken-2'>Día del Evento</p>
  162. <input id="icon_prefix" type="date" class="datepicker" name="dia"
  163. title="Se Necesita el Día" >
  164. </div>
  165.  
  166.  
  167. <div class='input-field col s12 m6'><p class='blue-text text-darken-2'>Hora del Evento</p>
  168. <input id="icon_prefix" type="time" name="hora_evento" autocomplete="off" title="Se Necesita la hora" >
  169. </div>
  170.  
  171.  
  172. <div class='input-field col s12 m6'>
  173. <p class='blue-text text-darken-2'>Cliente</p>
  174. <input type=text placeholder='Busqueda de clientes'
  175. autocomplete="off"  id="inputString" name='idcedula'>
  176.  
  177.  
  178.  
  179. </div>
  180.  
  181. <div class='center-align'>
  182. <div class='center-btn'><!-- botones -->
  183.  
  184. <div class='row'>
  185. <button class='btn waves-effect red accent-4
  186. btn-medium tooltipped' data-position='right'
  187. data-tooltip='Generar Contrato' type='submit' name='guardar'>
  188. <i class="material-icons">description</i></i>
  189. </button>
  190.  
  191. <input type='hidden' name='iddetalle_factura' value='iddetalle_factura'>
  192.  
  193.  
  194. </form>
  195. </div>
  196.  
  197.  
  198.  
  199.  
  200. <div class='row'>
  201. <a href="./contrato.php">
  202. <button class='btn waves-effect cyan deep-purple accent-4
  203. btn-medium tooltipped' data-position='right'
  204. data-tooltip='Volver a la lista de productos'
  205. id="submit" type="submit" >
  206. <i class='material-icons'>reply_all</i>
  207. </button></a>
  208. </div>
  209. <div class='row'>
  210. <a href='carro.php?id=$_SESSION[id]'>
  211. <button class='btn waves-effect cyan darken-4  
  212. btn-medium tooltipped' data-position='right'
  213. data-tooltip='Vaciar Carrito' type='reset' >
  214. <i class='tiny mdi-image-adjust'></i>
  215. </button></a>
  216.  
  217.  
  218.  
  219.  
  220. </div>
  221. </div><!-- fin botones -->
  222.  
  223.  
  224.  
  225. </div><!-- fin div colunna izquierda y colunna derecha -->
  226.  
  227. <br>
  228.  
  229. <br>
  230.  
  231. <br>
  232.  
  233.  
  234. <?php    
  235.     }
  236.       else
  237.  
  238. echo "<br>
  239. <br>
  240. <br>
  241. <br>
  242. <br>
  243. <div class='center-align'>
  244. <h5 class='red-text text-darken-4 center-align'>Ops, El carro
  245. está vacío, en breve sera redireccionado a la lista de productos</h4>
  246. </div>";
  247. // Redireccionar a contrato.php después de 5 segundos
  248. //header( "refresh:10; url=contrato.php" );
  249.  
  250.  
  251.  
  252.     ?>
__________________
yoclens avilan