Guest User

Untitled

a guest
Feb 25th, 2019
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. <head>
  2. <title>Universalistas</title>
  3. <meta charset="utf-8"/>
  4. <link rel="stylesheet" href="css/style.css"/>
  5. <link rel="shortcut icon" href="css/images/logo.png"/>
  6. </head>
  7.  
  8. </body>
  9.  
  10. <?php ob_start();
  11.  
  12. include("conection.php");
  13.  
  14. if(isset($_POST["send"]))
  15. {
  16.  
  17. function validate_mail($mail)
  18. {
  19. if (preg_match("/^[A-Za-z0-9-_.+%]+@[A-Za-z0-9-.]+.[A-Za-z]{2,4}$/", $mail)) return true;
  20. else return false;
  21. }//Fin funcion validate_mail
  22.  
  23. $no_blank = count_chars($_POST["user"], 1);
  24. if(!empty($no_blank[32])) echo "<script>alert('El campo usuario no debe contener espacios en blanco.');history.back();</script>";
  25. elseif(empty($_POST["user"])) echo "<script>alert('Ingresa tu usuario.');history.back();</script>";
  26. elseif(empty($_POST["password"])) echo "<script>alert('Ingresa una contraseña.');history.back();</script>";
  27. elseif(empty($_POST["name"])) echo "<script>alert('Ingresa tu nombre.');history.back();</script>";
  28. elseif(empty($_POST["last-name"])) echo "<script>alert('Ingresa tu apellido.');history.back();</script>";
  29. elseif($_POST["password"] != $_POST["rpassword"]) echo "<script>alert('Las contraseñas no coinciden.');history.back();</script>";
  30. elseif(!validate_mail($_POST["mail"])) echo "<script>alert('El e-mail es incorrecto.');history.back();</script>";
  31. else
  32. {
  33. $con = new mysqli("localhost", "universalistas", "u12345", "universalistas");
  34. $user = mysqli_real_escape_string($con, $_POST["user"]);
  35. $password = mysqli_real_escape_string($con, $_POST["password"]);
  36. $mail = mysqli_real_escape_string($con, $_POST["mail"]);
  37. $name = $_POST["name"];
  38. $lastname = $_POST["last-name"];
  39. $origin = $_POST["origin"];
  40. $area = $_POST["area"];
  41. $sql = mysqli_query($con, "SELECT user_name FROM user WHERE user_name='".$user."'");
  42. if(mysqli_num_rows($sql) > 0) echo "<script>alert('El usuario ya existe.');history.back();</script>";
  43. else
  44. {
  45. $password = md5($password); //Encriptacion md5
  46. $reg = mysqli_query($con, "INSERT INTO user (user_name, user_password, user_mail, name, last_name, origin, area)
  47. VALUES ('".$user."', '".$password."', '".$mail."', '".$name."', '".$lastname."', '".$origin."', '".$area."')");
  48. if($reg)
  49. {
  50. echo "<script>alert('Usuario registrado correctamente.');
  51. window.location.href = 'index.php';</script>";
  52. }
  53. else
  54. {
  55. echo"<script>alert('¡Ha ocurrido un error y no se registraron los datos!');
  56. window.location.href = 'index.php';</script>";
  57. }
  58. }
  59. }
  60. }
  61.  
  62. else {}
  63.  
  64. ob_end_flush() ?>
  65.  
  66. </body>
  67.  
  68. </html>
Add Comment
Please, Sign In to add comment