Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- $conn = mysqli_connect($servername, $username, $password, "coche");
- if ($_SERVER['REQUEST_METHOD'] === 'POST')
- {
- if (isset($_POST["marca"]))
- {
- $sql = "UPDATE `coche`.`coche` SET `marca`='".$_POST["marca"]."' WHERE `id`=" . $_GET['id'] . ";";
- mysqli_query($conn, $sql);
- }
- if (isset($_POST["modelo"]))
- {
- $sql = "UPDATE `coche`.`coche` SET `modelo`='".$_POST["modelo"]."' WHERE `id`=" . $_GET['id'] . ";";
- mysqli_query($conn, $sql);
- }
- if (isset($_POST["foto"]))
- {
- $sql = "UPDATE `coche`.`coche` SET `foto`='".$_POST["foto"]."' WHERE `id`=" . $_GET['id'] . ";";
- mysqli_query($conn, $sql);
- }
- header('Location: '. "/listarcoches.php");
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Editar coche</title>
- <meta charset="UTF-8">
- </head>
- <body>
- <form action="#" method="POST">
- <?php
- if ($_SERVER['REQUEST_METHOD'] === 'GET')
- {
- if (isset($_GET['id']))
- {
- $sql = "SELECT * from COCHE WHERE id = \"" . $_GET['id'] . "\"";
- $res = mysqli_query($conn, $sql);
- while ($arr = mysqli_fetch_array($res,MYSQLI_ASSOC))
- {
- foreach($arr as $key=>$valor) {
- if (($key == "marca")||($key == "modelo")||($key == "foto"))
- echo "<input name=\"".$key."\" type=\"text\" value=\"" . $valor . "\"></td>";
- if ($key == "foto")
- echo "<img src=\"" . $valor . "\">";
- }
- echo "<a href=\"borrarcoche.php?id=" . $_GET["id"] . "\">Borrar</a>";
- }
- }
- }
- ?>
- <input type="submit" value="Buscar">
- </from>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement