Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>Homepage</title>
- </head>
- <body>
- <?php
- $estado="form";
- if ($estado="form"){
- ?>
- <h1>Forms</h1>
- <h2>Registro</h2>
- <form method="POST" action="teste.php?area=registro">
- Nome: <input type="text" name="user"><br />
- Senha: <input type="password" name="password">
- <input type="submit" id="register">
- </form>
- <h2>Login</h2>
- <form method="POST" action="teste.php?area=login">
- Nome: <input type="text" name="user"><br />
- Senha: <input type="password" name="password">
- <input type="submit" id="login">
- </form>
- <?php
- }
- if(isset($_GET["area"])){
- $estado=$_GET["area"];
- if ($estado == "registro"){
- if((isset($_POST['user']) && $_POST['user']!="") && (isset($_POST['password']) && $_POST['password']!="")){
- $user = $_POST['user'];
- $password = $_POST['password'];
- $connection = mysql_connect("localhost", "root", "") or die("<p>Não foi possível se conectar ao banco de dados.</p>");
- mysql_select_db("cadastro");
- $exists = mysql_query("SELECT * FROM cadastro WHERE nome='$user';") or die("<p>Usuario $user ja eh cadastrado.</p>");
- if (mysql_num_rows($exists) == 0){
- mysql_query("INSERT INTO cadastro (nome, senha) VALUES ('$user', md5('$password'));");
- echo "<p>Usuario $user cadastrado com sucesso.</p>";
- }
- }
- else{
- echo "<p>Nome ou senha não especificados.</p>";
- }
- }
- if ($estado == "login"){
- }
- }
- ?>
- </body>
- </html>
Add Comment
Please, Sign In to add comment