Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.18 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>Ver producto</title>
  4. </head>
  5.  
  6. <body>
  7.  
  8. <form name"ver" action="ver.php" method="GET">
  9.     Id: <input type="text" name="id" /> <br/>
  10.     <input type="submit" name="submit" value="Ver">
  11. </form>
  12.  
  13. <?php
  14. // Nos conectamos al servidor de la base de datos
  15. mysql_connect("mysql.amarello.com.mx", "usuario", "password") or die(mysql_error());
  16. // Seleccionamos la base de datos
  17. mysql_select_db("cursoseguridad") or die(mysql_error());
  18.  
  19. // Si no mandaron nada se termina
  20. if (!isset($_GET['id'])) {
  21.     die("</body></html>");
  22. }
  23.  
  24. // Guardamos los parámetros que nos mandaron
  25. $id = $_GET['id'];
  26.  
  27. // Construimos la consulta
  28. $sql = "SELECT * FROM producto WHERE idproducto = '$id'";
  29.  
  30. // Ejecutamos la consulta
  31. $res = mysql_query($sql) or die(mysql_error());
  32.  
  33. // Si la consulta devolvió al menos un resultado
  34. if ($row = mysql_fetch_assoc($res)) {
  35. ?>
  36.  
  37. <table border="1">
  38.   <tr>
  39.     <th>Producto</th>
  40.     <th>Descripcion</th>
  41.   </tr>
  42.   <tr>
  43.     <td><?=$row['producto'] ?></td>
  44.     <td><?=$row['descripcion'] ?></td>
  45.   </tr>
  46. </table>
  47.  
  48. <?php
  49. }
  50. // Si la consulta no devolvió resultados
  51. else {
  52. ?>
  53.     <br/>No existe el producto
  54. <?php
  55. }
  56. ?>
  57.  
  58. </body>
  59. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement