Login.php
Código 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=utf-8" /> <title>Documento sin título</title> <link href="estilos.css" type="text/css" rel="stylesheet" /> <script type="text/javascript" language="javascript" src="funciones.js"></script> </head> <body> <h1>Comprobar el Registro</h1> <center> <form method="post" action="" name="form"> <table border="0"> <tr> <th colspan="2">Registrado?</th> </tr> <tr> <td width="100" height="50">Usuario</td><td width="165"><input type="text" name="user" /></td> </tr> <tr> <td width="100" height="50">Password</td><td><input type="password" name="pass" /></td> </tr> <tr> <td width="50" colspan="2">¿Olvidaste tu contraseña? <input type="submit" name="login" value="Log-in" style="float:right;" onclick="validar()"/></td> </tr> </table> </form> <?php require_once('class.php'); $Bd= new Bd('sm','root',''); if(isset($_POST["login"]) && $_POST["login"]=="Log-in"){ $log= new Login(); $log->registrado($_POST["user"],$_POST["pass"]); } ?> </center> </body> </html>
-----------------------
estilos.css
Código :
/*** Estilos de login.php ***/ body{ background:#C96; padding:7px; font: bold 15px "Palatino Linotype", "Book Antiqua", Palatino, serif; } table{ background:#96F; border-radius:7px; } td{ text-align:center; }
---------------------------
funciones.js
Código Javascript :
function validar(){ var form = document.form; if(form.user.value==0){ alert("ingrese su nombre"); form.user.value=""; form.user.focus(); return false; } if(form.pass.value==0){ alert("ingrese su password"); form.pass.value=""; form.pass.focus(); return false; } form.submit(); }
-------------------------------------
class.php
Código PHP :
<?php class Bd{ private $bd; private $bduser; private $bdpass; public function __construct($nombrebd,$bdusuario,$bdpassword){ $this->bdpass=$bdpassword; $this->bduser=$bdusuario; $this->bd=$nombrebd; mysql_connect('localhost',$bdusuario,$bdpassword)or die('No te conectaste :('); mysql_select_db($nombrebd)or die('no existe la base de datos'); } } class Login{ private $user; private $pass; public function registrado($usuario,$password){ $this->user=$usuario; $this->pass=$password; $sql="SELECT * FROM lista WHERE user='".$usuario."' AND pass='".$password."'"; $query=mysql_query($sql); $con="0"; while($filas=mysql_fetch_array($query)){ $con++; } if($con=="0"){ echo "Usuario no Registrado<br>"; echo "<a href='registro.php'>Registrarme!!!</a>"; }else{ echo "Aquél Usuario está Registrado!!"; } } } ?>
Código MySQL :
CREATE DATABASE sm; USE sm; CREATE TABLE `lista` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user` varchar(50) CHARACTER SET utf8 COLLATE utf8_spanish_ci NOT NULL, `pass` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `email` varchar(50) CHARACTER SET utf8 COLLATE utf8_spanish_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; INSERT INTO `lista` VALUES (1,'Juan','hola','[email protected]'); INSERT INTO `lista` VALUES (2,'fito','1234','[email protected]');
Haber si me dicen que puedo mejorar, aunque no crean me esforcé