Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function renderForm($id, $categoria, $foto, $titulo, $descripcion, $error)
- {
- ?>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
- <html>
- <head>
- <title>Edit Record</title>
- </head>
- <body>
- <?php
- if ($error != '')
- {
- echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
- }
- ?>
- <form action="" method="post" class="form-inline">
- <input type="hidden" name="id" value="<?php echo $id; ?>"/>
- <div align="center" style="height:500px;">
- <img src="#" width="165" height="77"><br/>
- <div class="form-group">
- <label for="ID">ID: </label> <?php echo $id; ?><br/>
- <strong>Categoria: </strong><select name="categoria" value="<?php echo $categoria ?>" class="form-control">
- <option value="perros">Perro</option>
- <option value="gatos">Gato</option>
- <option value="peces">Pez</option>
- <option value="aves">Ave</option>
- <option value="reptiles">Reptil</option>
- <option value="roedores">Roedor</option>
- <option value="productos">Producto</option>
- </select><br/>
- <strong>Foto: </strong><input type="text" name="foto" value="<?php echo $foto ?>" class="form-control"><br/>
- <strong>Titulo: </strong><input type="text" name="titulo" value="<?php echo $titulo ?>" class="form-control"><br/>
- <strong>Descripción: </strong><input type="text" name="descripcion" value="<?php echo $descripcion ?>" class="form-control"><br/>
- <input type="submit" name="submit" value="Enviar" class="btn btn-default"> </div>
- </form>
- </body>
- </html>
- <?php
- }
- include('include-db.php');
- if (isset($_POST['submit']))
- {
- if (is_numeric($_POST['id']))
- {
- $id = $_POST['id'];
- $categoria = mysql_real_escape_string(htmlspecialchars($_POST['categoria']));
- $foto = mysql_real_escape_string(htmlspecialchars($_POST['foto']));
- $titulo = mysql_real_escape_string(htmlspecialchars($_POST['titulo']));
- $descripcion = mysql_real_escape_string(htmlspecialchars($_POST['descripcion']));
- mysql_query("UPDATE posts SET categoria='$categoria', foto='$foto', titulo='$titulo', descripcion='$descripcion' WHERE ID='$id'")
- or die(mysql_error());
- header("Location: home.php");
- }
- else
- {
- echo 'Error!';
- }
- }
- else
- {
- if (isset($_GET['id']) && is_numeric($_GET['id']) && $_GET['id'] > 0)
- {
- $id = $_GET['id'];
- $result = mysql_query("SELECT * FROM posts WHERE ID=$id")
- or die(mysql_error());
- $row = mysql_fetch_array($result);
- if($row)
- {
- $categoria = $row['categoria'];
- $foto = $row['foto'];
- $titulo = $row['titulo'];
- $descripcion = $row['descripcion'];
- renderForm($id, $categoria, $foto, $titulo, $descripcion, '');
- }
- else
- {
- echo "No results!";
- }
- }
- else
- {
- echo 'Error!';
- }
- }
- ?>
Add Comment
Please, Sign In to add comment