0

Hello,
I have one table with user information contain unique ID and password. When user enters the ID and password in php login form, my php code should check that ID is already present or not. If it is present, my php code should check that the password is same as password for that ID in database. If it is same then "welcome.php" page should be open or "Invalid user ID or password " msg should be display.
It is my live project, so please reply as soon as possible.

Thanks,
Pooja.

4
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by Pooja J.
0

Pooja,

This is a simple login script you are asking for. Why don't you try few lines of code and post your errors here?

0
<?
ob_start();
extract($_POST);
extract($_REQUEST);
session_start();

$con=mysql_connect('localhost','root','');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
  mysql_select_db("databasename", $con);
if($_POST['username']!='' && $_POST['password']!='')
{
//echo $url;exit;
$select=mysql_query("select * from user_registration where username='$username' and password='$password'");
$count=mysql_num_rows($select);

if($count>0)
{
$fetch=mysql_fetch_array($select);
$_SESSION['user_id']=$fetch['auto_id'];

header("location:my_account.php");
}
else
{
$exists=1;
}
}


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="javascript">
function validate()
{
var uname=window.document.login.username.value;
if(window.document.login.username.value=='')
{
alert("enter username");
window.document.login.username.focus();
return false;
}
if(window.document.login.password.value=='')
{
alert("enter password");
window.document.login.password.focus();
return false;
}
else
{
return true;
}
}

</script>
</head>

<body>
<form name="login"  action="" method="post" onsubmit="return validate();">
          <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" >
		  <? if($exists==1)
		  {
		  ?>
		  <tr height="30">
              <td colspan="2"><span>Invalid Username or password<span></td>
            </tr>
		  <?
		  }
		  ?>
            <tr height="30">
              <td colspan="2"><input type="text" name="username"  value="" /></td>
            </tr>
            <tr height="30">
              <td colspan="2"><input type="passowrd"  name="password" value=""  /></td>
            </tr>
            <tr>
              <td  height="50"><br />
                </td>
              <td ><input type="submit" value="submit" name="submit"/></td>
            </tr>
          </table>
        </form>
</body>
</html>

change the connection settings and try it

0

Thanks, but where is your code.

Pooja,

This is a simple login script you are asking for. Why don't you try few lines of code and post your errors here?

0

Thanks, but where is your code.

He meant YOUR code. Guidelines ask that you provide your own code first as opposed to asking others to do all the work for you. It is unfortunate that somebody has felt it necessary to provide a complete solution, thereby circumventing the learning process. Oh well.

0

Actually, at the first sight I didnt understand his meaning.Thats why I am asking such question.
Second, I tried it form two days ,but i m fail to do it.Thats why I want fresh code.I am not expecting that members should do all work for me.

Thank,
Pooja.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.