Advertisement
Guest User

editarcoche.php

a guest
Dec 12th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. <?php
  2. $servername = "localhost";
  3. $username = "root";
  4. $password = "";
  5. $conn = mysqli_connect($servername, $username, $password, "coche");
  6. if ($_SERVER['REQUEST_METHOD'] === 'POST')
  7. {
  8.  
  9. if (isset($_POST["marca"]))
  10. {
  11. $sql = "UPDATE `coche`.`coche` SET `marca`='".$_POST["marca"]."' WHERE `id`=" . $_GET['id'] . ";";
  12. mysqli_query($conn, $sql);
  13. }
  14. if (isset($_POST["modelo"]))
  15. {
  16. $sql = "UPDATE `coche`.`coche` SET `modelo`='".$_POST["modelo"]."' WHERE `id`=" . $_GET['id'] . ";";
  17. mysqli_query($conn, $sql);
  18. }
  19. if (isset($_POST["foto"]))
  20. {
  21. $sql = "UPDATE `coche`.`coche` SET `foto`='".$_POST["foto"]."' WHERE `id`=" . $_GET['id'] . ";";
  22. mysqli_query($conn, $sql);
  23. }
  24. header('Location: '. "/listarcoches.php");
  25. }
  26. ?>
  27.  
  28. <!DOCTYPE html>
  29. <html>
  30. <head>
  31. <title>Editar coche</title>
  32. <meta charset="UTF-8">
  33. </head>
  34. <body>
  35. <form action="#" method="POST">
  36. <?php
  37.  
  38. if ($_SERVER['REQUEST_METHOD'] === 'GET')
  39. {
  40. if (isset($_GET['id']))
  41. {
  42. $sql = "SELECT * from COCHE WHERE id = \"" . $_GET['id'] . "\"";
  43. $res = mysqli_query($conn, $sql);
  44. while ($arr = mysqli_fetch_array($res,MYSQLI_ASSOC))
  45. {
  46. foreach($arr as $key=>$valor) {
  47. if (($key == "marca")||($key == "modelo")||($key == "foto"))
  48. echo "<input name=\"".$key."\" type=\"text\" value=\"" . $valor . "\"></td>";
  49. if ($key == "foto")
  50. echo "<img src=\"" . $valor . "\">";
  51. }
  52. echo "<a href=\"borrarcoche.php?id=" . $_GET["id"] . "\">Borrar</a>";
  53.  
  54. }
  55. }
  56. }
  57.  
  58. ?>
  59. <input type="submit" value="Buscar">
  60. </from>
  61. </body>
  62. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement