Ver Mensaje Individual
  #6 (permalink)  
Antiguo 03/06/2009, 15:44
Avatar de Avatar810
Avatar810
 
Fecha de Ingreso: agosto-2007
Ubicación: Por rumbos Regios
Mensajes: 485
Antigüedad: 16 años, 8 meses
Puntos: 23
Respuesta: Autentificación de usuarios

tenias correcta la idea solo se te fue un detalle
La condicion para usar header es no haber enviado nada a pantalla anteriormente (ni las cabeceras de html)

Sugiero este codigo

Código PHP:
<?
if (isset($_POST['enviar'])) 
{
    
$error="";
    
$name=$_POST['name'];
    
$password=$_POST['password'];

    
$connection mysql_connect("localhost""USUARIODB""PASS WORDDB") or die ("Unable to connect to server"); 
    
$db mysql_select_db("BASE_DE_DATOS"$connection) or die ("Unable to select database");  

    
// query the database to see if there is a record which matches
    
$query "select 1 from MITABLA where name='$name' and password='$password'";
    
$result mysql_query($query$connection) or die ("Query error");
    if(
mysql_num_rows($result)>0)
        
header("Location: QuezTal.php");
    else
        
$error="Usuario o Contraseña INCORRECTOS<br /><br />";
}
else
{
    
?>
    <html>
    <head>
    <style type="text/css">
        body {background-color:#000000; color:#FF6600}
    </style>
    </head>
    <body>
        <h2> Esta p&aacute;gina es secreta </h2>
        <?= $error?>
        <form method="post" action="secretdb.php">
            Username:<br>
            <input type="text" name="name">
            <br>
            Password: <br>
            <input type="password" name="password">
            <br>
            <input type="submit" name="enviar" value="Enviar informacion">
        </form>
    </body>
    </html>
    <?
}
?>
__________________
Una demo siempre funcionará correctamente hasta que toque algo tu (hasta ahora) cliente.
Avatar810