Guest User

Untitled

a guest
Dec 11th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. <html>
  2.  
  3. <head>
  4. <title>Homepage</title>
  5. </head>
  6.  
  7. <body>
  8. <?php
  9. $estado="form";
  10.  
  11. if ($estado="form"){
  12. ?>
  13.  
  14. <h1>Forms</h1>
  15.  
  16. <h2>Registro</h2>
  17. <form method="POST" action="teste.php?area=registro">
  18. Nome: <input type="text" name="user"><br />
  19. Senha: <input type="password" name="password">
  20. <input type="submit" id="register">
  21. </form>
  22.  
  23. <h2>Login</h2>
  24. <form method="POST" action="teste.php?area=login">
  25. Nome: <input type="text" name="user"><br />
  26. Senha: <input type="password" name="password">
  27. <input type="submit" id="login">
  28. </form>
  29.  
  30. <?php
  31. }
  32.  
  33. if(isset($_GET["area"])){
  34. $estado=$_GET["area"];
  35.  
  36. if ($estado == "registro"){
  37. if((isset($_POST['user']) && $_POST['user']!="") && (isset($_POST['password']) && $_POST['password']!="")){
  38. $user = $_POST['user'];
  39. $password = $_POST['password'];
  40.  
  41. $connection = mysql_connect("localhost", "root", "");
  42. if($connection){
  43. mysql_select_db("cadastro");
  44.  
  45. $exists = mysql_query("SELECT * FROM cadastro WHERE nome='$user';");
  46.  
  47. if (mysql_num_rows($exists) == 0){
  48. mysql_query("INSERT INTO cadastro (nome, senha) VALUES ('$user', md5('$password'));");
  49. echo "<p>Usuario $user cadastrado com sucesso.</p>";
  50. }
  51.  
  52. else{
  53. echo "<p> Usuario $user ja eh cadastrado.</p>";
  54. }
  55. }
  56.  
  57. else{
  58. echo "<p>Não foi possível se conectar ao banco de dados.</p>";
  59. }
  60. }
  61.  
  62. else{
  63. echo "<p>Nome ou senha não especificados.</p>";
  64. }
  65. }
  66. if ($estado == "login"){
  67. }
  68. }
  69. ?>
  70. </body>
  71.  
  72. </html>
Add Comment
Please, Sign In to add comment