vineet2011
07-22-2012, 11:01 AM
hi i am new in php
i am stuck in the login code in username and password validation code
in this code if we dont enter the username and password then also it allows to login successfully
the code is
<?php
include('config.inc');
mysql_connect($hostname, $_username, $_password) or DIE(mysql_error());
mysql_select_db($_dbname) or DIE(mysql_error());
$u=trim($_POST['username']);
$p=trim($_POST[password]);
echo"<br>--$u--$p--";
if($u="" && $p="")
{
echo("not allowed");
}
else
{
if($u!="" && $p!="");
{
echo"<br><b>---$u</b>";
$query="select * from user_table where username='$u'";
$res=mysql_query($query) or DIE(mysql_error());
$final=mysql_fetch_array($res);
$pass=$final['password'];
if($_POST['password']!=$pass)
{
echo"<p><font color=\"red\">Incorrect username or password</font></p>";
}
else
{
$uname=$final['username'];
$type=$final['usertype'];
$_POST['op']="allowed";
echo"yo";
echo" Success $uname $type $_POST[op]";
//sesson_start();
$_SESSION['username']=$_POST['username'];
$_SESSION['permitted']="true";
$_SESSION['type']=$type;
//header("Location:new.php");
}
}
}
?>
i am stuck in the login code in username and password validation code
in this code if we dont enter the username and password then also it allows to login successfully
the code is
<?php
include('config.inc');
mysql_connect($hostname, $_username, $_password) or DIE(mysql_error());
mysql_select_db($_dbname) or DIE(mysql_error());
$u=trim($_POST['username']);
$p=trim($_POST[password]);
echo"<br>--$u--$p--";
if($u="" && $p="")
{
echo("not allowed");
}
else
{
if($u!="" && $p!="");
{
echo"<br><b>---$u</b>";
$query="select * from user_table where username='$u'";
$res=mysql_query($query) or DIE(mysql_error());
$final=mysql_fetch_array($res);
$pass=$final['password'];
if($_POST['password']!=$pass)
{
echo"<p><font color=\"red\">Incorrect username or password</font></p>";
}
else
{
$uname=$final['username'];
$type=$final['usertype'];
$_POST['op']="allowed";
echo"yo";
echo" Success $uname $type $_POST[op]";
//sesson_start();
$_SESSION['username']=$_POST['username'];
$_SESSION['permitted']="true";
$_SESSION['type']=$type;
//header("Location:new.php");
}
}
}
?>