Ver Mensaje Individual
  #3 (permalink)  
Antiguo 30/09/2009, 08:36
Avatar de xempro
xempro
 
Fecha de Ingreso: marzo-2007
Ubicación: Chile
Mensajes: 222
Antigüedad: 17 años, 1 mes
Puntos: 6
Respuesta: Validar usuario y contraseña

Código PHP:
<html>
    <head>
        <title> Login </title>
    </head>
    <body>
        <div align=center>
        <h1 align=center> Acceso de usuarios: </h1>
        <hr>
        <?php if (!$_POST['Ingresar']){ ?>
        <form method=post action="login.php">
            Usuario: <input type="text" name="username"><br />
            Contrase&ntilde;a: <input type="password" name="password"><br />
            <input type="submit" value="Ingresar" name="Ingresar">&nbsp;<input type="reset" value="Borrar"><br />
        </form>
        <?php
        
} else {
        if (isset(
$_POST['username']) || isset($_POST['password'])){
            echo 
"Debe ingresar un Usuario y Contrase&ntilde;a";
        } else {
            include (
'conectar.php');
            
$conectar;
            
extract($_POST);
            
mysql_select_db('nombremibasededatosdb');
            
$consulta="select * from Usuarios where Usuario='$username' and Passwodr='$password'";
            
$resultado=mysql_query($consulta);
            
$rows mysql_num_rows($resultado);
            if (
$rows == 1)
                echo 
"Bienvenido " $_POST['correo'];
            else if (
$rows == 0)
                echo 
"Usuario o contrase&ntilde;a inv&aacute;lidos";
            else
                echo 
"Error de conexi&oacute;n a la base de datos";
        }
        
?>
        </div>
    </body>
</html>