Tema: Login en PHP
Ver Mensaje Individual
  #3 (permalink)  
Antiguo 28/07/2012, 15:36
lincolnf_2
 
Fecha de Ingreso: abril-2011
Ubicación: lima
Mensajes: 134
Antigüedad: 13 años
Puntos: 3
Respuesta: Login en PHP

<?php
include("conexion.php");
$cn=conectarDB();
$res=0;
$stm=$cn->prepare("select count(*) from usuarios where nombre=? and clave=?");
$stm->bind_param("ss",$_POST["usuario"],$_POST["clave"]);
$stm->execute();
$stm->bind_result($res);
$stm->fetch();

if ($res==1) {
session_start();
$_SESSION["usuario"]=$_POST["usuario"];
header("location: Bienvenido.php");
}

else{
header("location: index.php");
}

?>

conexion.php

<?php
function conectar_DB(){
$cn=new mysqli("localhost","root","mipassword","prueba");
if (mysqli_connect_errno()) {
echo 'Error al conectar a la base de datos'. mysqli_connect_errno();
exit();
}
return $cn;
}
?>

suerte...
__________________
Solitary wolf..[email protected]