Jump to content
Fórum Script Brasil
  • 0

Cadastro Php + Mysql


Question

3 answers to this question

Recommended Posts

  • 0

Cara eu tenho um sistema mais ou menos desse jeito que você descreveu segue script para analize...

Obs: Créditos do tuto (Aguinelo Pedroso)

Criando a tabela:

CREATE TABLE `usuarios`

( `id` INT NOT NULL AUTO_INCREMENT ,

`nome` VARCHAR( 50 ) NOT NULL ,

`email` VARCHAR( 60 ) NOT NULL ,

`login` VARCHAR( 20 ) NOT NULL ,

`senha` VARCHAR( 8 ) NOT NULL ,

PRIMARY KEY ( `id` )

);

INSERT INTO `usuarios` ( `id` , `nome` , `email` , `login` , `senha` ) VALUES

( '', 'Usuario de teste', '[email protected]', 'usuario', 'teste');

Cadastro.html

<html>

<head>

<title>Documento sem t&iacute;tulo</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

<body>

<form name="form1" method="post" action="cadastro.php">

<div align="center">

<p>&nbsp;</p><table width="25%" border="1">

<tr>

<td><div align="right">Nome:

<input name="nome" type="text" id="nome" size="20">

</div></td>

</tr>

<tr>

<td><div align="right">Email:

<input name="email" type="text" id="email" size="20">

</div></td>

</tr>

<tr>

<td><div align="right">Login:

<input name="login" type="text" id="login" size="20">

</div></td>

</tr>

<tr>

<td><div align="right">Senha:

<input name="senha" type="password" id="senha" size="20">

</div></td>

</tr>

</table>

</div>

</form>

</body>

</html>

Cadastro.php

<?php

include"config.php";

$nome = $_POST['nome'];

$email = $_POST['email'];

$login = $_POST['login'];

$senha = $_POST['senha'];

$x = mysql_query("INSERT INTO usuarios(nome,email,login,senha) VALUES ('$nome', '$email', '$login', '$senha')");

if($x){

echo " Usuário cadastrado com sucesso!!! ";

echo "<meta http-equiv=refresh' content='2;URL=cadastrar.php'>";

}else{

echo "Erro no Cadastro";

echo "<meta http-equiv='refresh' content='2;URL=cadastrar.php'>";

}

?>

Login.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Autenticação Simples de Usuário</title>

</head>

<body>

<form action="auth.php" name="autenticacao" method="post">

<table style="width:100%; height:100%; border:0px; text-align:center">

<tr> <td>

<table width="200" border="0" align="center">

<tr>

<td width="50">Login:</td> <td width="140"><input type="text" name="login" size="20" maxlength="20" />

</td> </tr>

<tr>

<td>Senha:</td> <td><input type="password" name="senha" size="20" maxlength="8" />

</td> </tr> <tr>

<td colspan="2"><input type="submit" name="entra" value="Entrar" />

</td> </tr>

</table>

</td>

</tr>

</table>

</form>

</body>

</html>

Auth.php

<?php

$login = $_POST['login];

$senha = $_POST['senha'];

$conn = mysql_connect("localhost", "root", "") or die("Impossivel conectar"); // conecta o banco

if($conn) {

mysql_select_db("artigos", $conn);

}

$sql = "SELECT id, nome FROM usuarios WHERE login = '$login' AND senha = '$senha'"; // seleciona a tabela

$rs = mysql_query($sql, $conn);

$num = mysql_num_rows($rs);

if($num > 0)

{

$rst = mysql_fetch_array($rs);

$id = $rst["id"];

$nome = $rst["nome"];

//Inicia a sessão

session_start();

sessão$_SESSION["id"] = $id;

$_SESSION["nome"] = $nome;

$_SESSION["login"] = $login;

mysql_close($conn); // fecha a conexão

header("Location:index.php");

}else{

mysql_close($conn);

echo "<b>Usuário ou senha inválidos</b>";

echo "<meta http-equiv=refresh' content='3;URL=login.php'>";

}

?>

Index.php

<?php

//Inclui o arquivo de verificação

include_once("verifica.php");

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title></head>

<body><div>Olá : <b><?php echo $_SESSION['nome] ?></b></div><br /><br /><a href="destroy.php">Sair</a></body></html>

Verifica.php

<?php

//Inicia a sessão

session_start(); //Verifica se há dados ativos na sessão

if(empty($_SESSION["id"]) || empty($_SESSION["nome"]) || empty($_SESSION["login"] )) {

header("Location:login.php");

}

?>

Destroy.php

<?php

//Inicia a sessão

session_start(); //Elimina os dados da sessão

session_unregister($_SESSION['id]);

session_unregister($_SESSION['nome']);

session_unregister($_SESSION['login']);

//Encerra a sessão

session_destroy();

header("Location:login.php");

?>

Para a pagina ser acessada apenas com um login basta incluir esse código no inicio das paginas.

<?php

Include_once("verifica.php");

?>

Espero ter ajudado...

Link to post
Share on other sites
  • 0

provavelmente esse arquivo "config.php" faz a conexao com o banco de dados. use algo desse tipo:

<?php

$hostname_conexao = "url";

$database_conexao = "db";

$username_conexao = "user";

$password_conexao = "pass";

$conexao = mysql_connect($hostname_conexao, $username_conexao, $password_conexao) or trigger_error(mysql_error(),E_USER_ERROR);

$db=mysql_select_db("db",$conexao);

?>

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Cloud Computing


  • Forum Statistics

    • Total Topics
      149296
    • Total Posts
      645693
×
×
  • Create New...