Ver Mensaje Individual
  #1 (permalink)  
Antiguo 03/12/2010, 18:48
tazzwt
 
Fecha de Ingreso: marzo-2010
Mensajes: 432
Antigüedad: 14 años, 1 mes
Puntos: 11
Como restar cantidad a un articulo php mysql

Hola tengo una pequeña base de datos de libros y sus cantidades.

La idea es comprar y vender.

Si la cantidad es menor a la que se encuentra en stock no se pueda comprar.

Como lo puedo hacer eso ?

Ingreso la cantidad y le doy en comprar.



Código PHP:
Ver original
  1. <html>
  2. <head>
  3.    <title>Libros</title>
  4. </head>
  5. <body>
  6.  
  7.  <table width="630" border="0">
  8.   <tr>
  9.     <td>Titulo</td>
  10.     <td>Stock</td>
  11.     <td>Precio</td>
  12.     <td>Cantidad</td>
  13.  </tr>
  14.   <tr>
  15.  
  16. <?php
  17.    include("conex.php");
  18.    $link=Conectarse();
  19.    $result=mysql_query("select * from libros",$link);
  20. ?>
  21.  
  22.  
  23. <?php
  24.  
  25.  
  26.    while($row = mysql_fetch_array($result)) {
  27.  
  28.     $id = $row["id"];
  29.     $titulos  = $row["titulos"];
  30.     $precio  = $row["precio"];
  31.     $autor  = $row["autor"];
  32.     $titulos  = $row["titulos"];
  33.     $cantidad = $row["cantidad"];
  34.  
  35.       echo "
  36.         <td>$titulos</td>
  37.         <td>$cantidad </td>
  38.         <td>$$precio</td>
  39.         <td><input type='text' name='textfield' size='5' maxlength='5'/></td>
  40.         <td><input type='submit' name='button' value='Comprar' /></td>
  41.      </tr>
  42.       ";
  43.    }
  44.  
  45.    mysql_free_result($result);
  46.    mysql_close($link);
  47. ?>
  48.  
  49. </table>
  50. </body>
  51. </html>

MiBase


Código MySQL:
Ver original
  1. -- phpMyAdmin SQL Dump
  2. -- version 2.10.3
  3. -- http://www.phpmyadmin.net
  4. --
  5. -- Servidor: localhost
  6. -- Tiempo de generación: 03-12-2010 a las 20:06:42
  7. -- Versión del servidor: 5.0.51
  8. -- Versión de PHP: 5.2.6
  9.  
  10. SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
  11.  
  12. --
  13. -- Base de datos: `test002`
  14. --
  15.  
  16. -- --------------------------------------------------------
  17.  
  18. --
  19. -- Estructura de tabla para la tabla `libros`
  20. --
  21.  
  22. CREATE TABLE `libros` (
  23.   `id` int(11) NOT NULL auto_increment,
  24.   `titulos` varchar(60) default NULL,
  25.   `precio` decimal(10,2) default NULL,
  26.   `autor` varchar(60) default NULL,
  27.   `editorial` varchar(60) default NULL,
  28.   `cantidad` int(4) default NULL,
  29.   PRIMARY KEY  (`id`)
  30. ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=12 ;
  31.  
  32. --
  33. -- Volcar la base de datos para la tabla `libros`
  34. --
  35.  
  36. INSERT INTO `libros` VALUES (1, 'Como Programar En C++ 6ª Edicion', 50000.00, 'Deitel, Harvey M.', 'Prentice Hall', 15);
  37. INSERT INTO `libros` VALUES (2, 'Como Programar En Java 7º Edicion', 50000.00, 'Deitel, Harvey M.', 'Prentice Hall', 3);
  38. INSERT INTO `libros` VALUES (3, 'Estructuras De Datos En Java', 30000.00, 'Joyanes Aguilar, Luis', 'Mc Graw Hill', 7);
  39. INSERT INTO `libros` VALUES (4, 'Fundamentos De Java 3° Edicion', 31000.00, 'Schildt', 'Mc Graw Hill', 8);
  40. INSERT INTO `libros` VALUES (5, 'Java 2 Distribuido Desarrollo De Bases', 25000.00, 'Birnam', 'Prentice Hall', 15);
  41. INSERT INTO `libros` VALUES (6, 'Java 2 Serie Práctica', 21000.00, 'García Bermejo, José Rafael', 'Prentice Hall', 6);
  42. INSERT INTO `libros` VALUES (7, 'Java Para Estudiantes', 30000.00, 'Bell', 'Prentice Hall', 0);
  43. INSERT INTO `libros` VALUES (8, 'Programacion Algoritmos Y Ejercicios Resueltos En Java', 30000.00, 'Camacho', 'Prentice Hall', 3);
  44. INSERT INTO `libros` VALUES (9, 'Programacion En C /C++ Java Y Uml', 55000.00, 'Joyanes Aguilar, Luis', 'Mc Graw Hill', 4);
  45. INSERT INTO `libros` VALUES (10, 'Programacion Java. Introduccion A La Programacion', 46000.00, 'Wu, C. Thomas', 'Mc Graw Hill', 80);
  46. INSERT INTO `libros` VALUES (11, 'Soluciones De Programacion Java', 50000.00, 'Schildt', 'Mc Graw Hill', 7);