daily pastebin goal
68%
SHARE
TWEET

Untitled

a guest Sep 23rd, 2016 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. id    addtags
  2. ----  ------------
  3.  1     html, php
  4.    
  5. id    addtags
  6. ----  ------------
  7.  1     html, php
  8.    
  9. <?php
  10.  
  11. if (isset($_POST['tags']) && !empty($_POST['tags'])) {
  12.     $tags = $_POST['tags'];
  13.  
  14.     $host = "localhost";
  15.     $usuario = "root";
  16.     $clave = "";
  17.     $basedatos = "tags";
  18.     $tabla = "tags";
  19.  
  20.     $mysqli = mysqli_connect($host, $usuario, $clave, $basedatos);
  21.     if (mysqli_connect_errno($mysqli)) {
  22.         die( "Error al conectar a MySQL: " . mysqli_connect_error() );
  23.     }
  24.  
  25.     $sentencia = $mysqli->prepare("INSERT INTO $tabla (id, addtags) VALUES (?, ?)");
  26.     $sentencia->bind_param('is', $id, $tags);
  27.     $sentencia->execute();
  28.  
  29.  
  30.     $sentencia = null;
  31.     $mysqli = null;
  32.  
  33.     echo "Se grab√≥ la etiqueta tags";
  34. }
  35.  
  36. ?>
  37.    
  38. <?php
  39.  
  40.   $servername = "localhost";
  41.   $username = "root";
  42.   $password = "";
  43.   $dbname = "tags";
  44.  
  45.   $conn = new mysqli($servername, $username, $password, $dbname);
  46.  
  47.   if ($conn->connect_error) {
  48.     die("Connection failed: " . $conn->connect_error);
  49.   }
  50.  
  51.   $sql = "SELECT id, addtags FROM tags";
  52.   $result = $conn->query($sql);
  53.  
  54.   if ($result->num_rows > 0) {
  55.  
  56.     while($row = $result->fetch_assoc()) {
  57.       $datotags = $row["addtags"];
  58.       $tags = explode(', ', $datotags);
  59.       $resultado = '';
  60.       foreach ($tags as &$tag) {
  61.         $resultado .= "n" . '<a href="example.com/tags/'.$tag.'">'.$tag.'</a>' ;
  62.       }
  63.  
  64.       echo $resultado;
  65.     }
  66.   }else {
  67.     echo "0 results";
  68.   }
  69.  
  70.   $conn->close();
  71.  
  72. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top