Advertisement
MizunoBrasil

Insert rápido

Dec 21st, 2022 (edited)
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.59 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="pt-br">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.     <title>Document</title>
  8. </head>
  9. <body>
  10.    
  11.     <?php
  12.         $mysqli = new mysqli('localhost', 'root', '', '0001');
  13.         if ($mysqli->connect_errno) {
  14.             echo 'Erro ao conectar ao banco de dados' . $mysqli->connect_error;
  15.         }
  16.  
  17.         if ($_POST) {
  18.            
  19.             if ($nome =$_POST['nome']) {                
  20.                 $query = "INSERT INTO usuarios (nome,data,horario) values('$nome', NOW(), NOW())";
  21.                 $res = $mysqli->query($query);
  22.                 if ($res) {
  23.                     $mensagem = "Cadastrado com sucesso!";
  24.                     header("Location:index.php");
  25.                 }
  26.             }
  27.         }
  28.  
  29.         $res = $mysqli->query("SELECT * FROM usuarios");
  30.     ?>
  31.     <h1>Cadastro rápido de links</h1>
  32.  
  33.     <h3>Links cadastrados</h3>
  34.     <ul>
  35.         <?php while ($row = $res->fetch_assoc()) { ?>            
  36.             <li><a href="<?php echo $row["nome"]; ?>" target="_blank"><?php echo $row["nome"]; ?></a></li>
  37.             <!-- <li> <?php echo $row['nome'] ?></li> -->
  38.         <?php } ?>
  39.     </ul>
  40.  
  41.     <hr>
  42.     <p>Cadastrar link abaixo: </p>  
  43.     <form action="index.php" method="post">
  44.         <label>URL</label>
  45.         <input type="text" name="nome">
  46.         <input type="submit" value="Salvar">
  47.     </form>
  48.     <?php if (!empty($mensagem)) {
  49.         echo $mensagem;
  50.     } ?>
  51.  
  52. </body>
  53. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement