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.

Recommended Answers

All 5 Replies

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?

<?
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

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?

Member Avatar for diafol

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.