Guest User

Untitled

a guest
Feb 27th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. <?php
  2. require 'database.php';
  3. $message = '';
  4. if (!empty($_POST['usuario']) && !empty($_POST['password'])) {
  5. $sql = "INSERT INTO usuarios (usuario, email, password) VALUES (:usuario, :email, :password)";
  6. $stmt = $conn -> prepare($sql);
  7. $stmt -> bindParam(':usuario',$_POST['usuario']);
  8. $password = password_hash($_POST['password'], PASSWORD_BCRYPT);
  9. $stmt -> bindParam(':password',$_POST['password']);
  10.  
  11. if ($stmt -> execute()) {
  12. $message = 'Se ha creado su cuenta satisfactoriamente en la pagina';
  13. }
  14. else {
  15. $message = 'Lo sentimos, pero ha ocurrido un problema con la base de datos';
  16. }
  17. }
  18. ?>
  19. <!doctype html>
  20. <html lang="en">
  21. <head>
  22. <meta charset="UTF-8">
  23. <title>Registrarse</title>
  24. <link rel="stylesheet" href="assets/css/style.css">
  25. </head>
  26. <body>
  27. <?php require 'partials/header.php' ?>
  28. <?php if (!empty($message)):
  29. ?>
  30. <p><?= $message ?></p>
  31. <?php
  32. endif;
  33. ?>
  34. <h1>Registrarse</h1>
  35. <span>ó <a href="login.php">Iniciar Sesión</a></span>
  36. <form action="signup.php" method="POST">
  37. <input type="text" name="usuario" placeholder="Usuario">
  38. <input type="text" name="email" placeholder="Email">
  39. <input type="password" name="password" placeholder="Contraseña">
  40. <input type="password" name="confirm_password" placeholder="Confirme la contraseña">
  41. <input type="submit" value="Enviar">
  42. </form>
  43. </body>
  44. </html>
  45.  
  46. <?php
  47. $server = 'localhost';
  48. $username = 'root';
  49. $password = '';
  50. $database = 'usuarios';
  51. try {
  52. $conn = new PDO("mysql:host=$server;dbname=$database;", $username, $password);
  53. } catch (PDOException $e) {
  54. die('Connection Failed: ' . $e->getMessage());
  55. }
  56. ?>
Add Comment
Please, Sign In to add comment