Guest User

PH

a guest
Dec 25th, 2015
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.09 KB | None | 0 0
  1.  <?php
  2.      function renderForm($id, $categoria, $foto, $titulo, $descripcion, $error)
  3.      {
  4.      ?>
  5.      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  6.      <html>
  7.      <head>
  8.      <title>Edit Record</title>
  9.      </head>
  10.      <body>
  11.      <?php
  12.      if ($error != '')
  13.      {
  14.      echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
  15.      }
  16.      ?>
  17.      
  18.      <form action="" method="post" class="form-inline">
  19.      <input type="hidden" name="id" value="<?php echo $id; ?>"/>
  20.      <div align="center" style="height:500px;">
  21.      <img src="#" width="165" height="77"><br/>
  22.      <div class="form-group">
  23.     <label for="ID">ID: </label> <?php echo $id; ?><br/>
  24.     <strong>Categoria: </strong><select name="categoria" value="<?php echo $categoria ?>" class="form-control">
  25.         <option value="perros">Perro</option>
  26.         <option value="gatos">Gato</option>
  27.         <option value="peces">Pez</option>
  28.         <option value="aves">Ave</option>
  29.         <option value="reptiles">Reptil</option>
  30.         <option value="roedores">Roedor</option>
  31.         <option value="productos">Producto</option>
  32.     </select><br/>
  33.     <strong>Foto: </strong><input type="text" name="foto" value="<?php echo $foto ?>" class="form-control"><br/>
  34.     <strong>Titulo: </strong><input type="text" name="titulo" value="<?php echo $titulo ?>" class="form-control"><br/>
  35.     <strong>Descripción: </strong><input type="text" name="descripcion" value="<?php echo $descripcion ?>" class="form-control"><br/>
  36.      <input type="submit" name="submit" value="Enviar" class="btn btn-default"> </div>
  37.      </form>
  38.      </body>
  39.      </html>
  40.      <?php
  41.      }
  42.    
  43.    
  44.    
  45.     include('include-db.php');
  46.       if (isset($_POST['submit']))
  47.      {
  48.      if (is_numeric($_POST['id']))
  49.      {
  50.      $id = $_POST['id'];
  51.      $categoria = mysql_real_escape_string(htmlspecialchars($_POST['categoria']));
  52.      $foto = mysql_real_escape_string(htmlspecialchars($_POST['foto']));
  53.      $titulo = mysql_real_escape_string(htmlspecialchars($_POST['titulo']));
  54.      $descripcion = mysql_real_escape_string(htmlspecialchars($_POST['descripcion']));
  55.    
  56.      
  57.      mysql_query("UPDATE posts SET categoria='$categoria', foto='$foto', titulo='$titulo', descripcion='$descripcion' WHERE ID='$id'")
  58.      or die(mysql_error());
  59.       header("Location: home.php");
  60.      }
  61.      else
  62.      {
  63.      echo 'Error!';
  64.      }
  65.      }
  66.      else
  67.      {
  68.      
  69.      if (isset($_GET['id']) && is_numeric($_GET['id']) && $_GET['id'] > 0)
  70.      {
  71.      $id = $_GET['id'];
  72.      $result = mysql_query("SELECT * FROM posts WHERE ID=$id")
  73.      or die(mysql_error());
  74.      $row = mysql_fetch_array($result);
  75.      
  76.     if($row)
  77.      {
  78.      
  79.      $categoria = $row['categoria'];
  80.      $foto = $row['foto'];
  81.      $titulo = $row['titulo'];
  82.      $descripcion = $row['descripcion'];
  83.    
  84.      
  85.      renderForm($id, $categoria, $foto, $titulo, $descripcion, '');
  86.      }
  87.      else
  88.      {
  89.      echo "No results!";
  90.      }
  91.      }
  92.      else
  93.      {
  94.      echo 'Error!';
  95.      }
  96.      }
  97.     ?>
Add Comment
Please, Sign In to add comment