Estoy haciendo un codigo de autentificason de usuario, funciona bien pero al identificar usuarios que no existen empieza el problema.
Este es el codigo:
Código PHP:
<?php
if($_POST){
session_start();
/////////////////////
$base="---";
$con=mysql_connect('localhost','root',);
mysql_select_db($base,$con);
//////////////////////
if($_POST['us']==NULL)echo "<script>location='index.php?mensaje=4'</script>" ;
if($_POST['clave']==NULL)echo "<script>location='index.php?mensaje=3&n=$us'</script>" ;
$checkuser = mysql_query("SELECT nick FROM users WHERE nick='".$_POST['us']."'",$con) or die(mysql_error());
$username_exist = mysql_num_rows($checkuser) or die(mysql_error());
$query = mysql_query("SELECT nick,clave FROM users WHERE nick = '".$_POST['us']."'",$con) or die(mysql_error());
$data = mysql_fetch_array($query);
///////////////////////
if($username_exist>0){
if($data['clave'] != $_POST['clave'])exit("<script>location='index.php?mensaje=0&n=$us'</script>") ;
session_register('log');
$_SESSION['log']=$_POST['us'];
echo "<script>location='op.php'</script>" ;
exit();
}
else{
echo "<script>location='index.php?mensaje=1'</script>" ;
}
}
?>
Código PHP:
<?php
if($_POST){
session_start();
/////////////////////
$base="---";
$con=mysql_connect('localhost','root',);
mysql_select_db($base,$con);
//////////////////////
if($_POST['us']==NULL)echo "<script>location='index.php?mensaje=4'</script>" ;
if($_POST['clave']==NULL)echo "<script>location='index.php?mensaje=3&n=$us'</script>" ;
$checkuser = mysql_query("SELECT nick FROM users WHERE nick='".$_POST['us']."'",$con) or die(mysql_error());
$username_exist = mysql_num_rows($checkuser) or die(mysql_error());
$query = mysql_query("SELECT nick,clave FROM users WHERE nick = '".$_POST['us']."'",$con) or die(mysql_error());
$data = mysql_fetch_array($query);
///////////////////////
if($username_exist>0){
if($data['clave'] != $_POST['clave'])exit("<script>location='index.php?mensaje=0&n=$us'</script>") ;
session_register('log');
$_SESSION['log']=$_POST['us'];
echo "<script>location='op.php'</script>" ;
exit();
}
//else{
echo "<script>location='index.php?mensaje=1'</script>" ;
//}
}
?>
Gracias
Salu2
