Ver Mensaje Individual
  #19 (permalink)  
Antiguo 09/03/2011, 16:31
Avatar de jotaincubus
jotaincubus
 
Fecha de Ingreso: mayo-2005
Ubicación: Medellin - Colombia
Mensajes: 1.797
Antigüedad: 19 años
Puntos: 394
Respuesta: Codigo php para iniciar Sesion

Cita:
Iniciado por bariedto Ver Mensaje
me quedaria asi,.........

<?php
session_start();
if($_POST)
{
include('cn_conexion.php');
$nombre=$_POST['txtNombre'];
$clave=$_POST['txtclave'];
mysql_select_db('control', $conexion);
$sql="select * from usuarios where nombre='".$nombre."' and clave='".$clave."'";
$consulta=mysql_query($sql,$conexion);
$filas=mysql_num_rows($consulta);
if($consulta > 0)
{
session_start();
$_SESSION['usuario']=$nombre;
header("Location:portal.php");
}
else
{
header("Location:error.php");
}
}
?>
<html>
<head>
<title>Acceso</title>
</head>
<body>
<h1>Acceso Restringido</h1><br>
<hr>
<i>Por favor, ingrese su nombre de usuario y su clave </i><br>
<form name='f1' method='POST' action='conexion_usuario.php'>
<table border='0'>
<tr>
<td align='right'>Nombre de usuario</td>
<td align='left'><input type='textfield' name='txtNombre'></td>
</tr>
<tr>
<td align='right'>Clave</td>
<td align='left'><input type='password' name='txtclave'></td>
</tr>
<tr>
<td colspan='2' align='center'><input type='submit' value='ingresar'></td>
</tr>
</table>
<hr>
</form>
</body>
</html>



pero si lo pongo asi.....me redirecciona de inmediato a la pagina PORTAL.php..sin antes pedrime el usuario y la clave....pork???? TESEO----GATORv
bueno amigo para mi que eso esta sucediendo por el IF que tienes para verificar si se presiono el boton enviar.

Colocale un nombre al boton submit asi:

<input type='submit' name="submit" value='ingresar'>

Despues cambia esto if($_POST) por esto:

if (isset($_POST['submit']))

y asi verificaras bien si el usuario presiono el boton enviar, espero atento tu respuesta.
__________________
Por que existe gente que no agradece después de que se le ha brindado tiempo y ayuda ???