Page 1 of 1

Prob in login Page

Posted: Thu Mar 22, 2012 1:20 am
by GaneshPrasad
In login page required dropdown option it means admin can select username,password and select the admin from dropdown then go for home page. I have written php code but it is not workin pls sir help me.the code is

Code: Select all

<?php
include("connection.php");
      if($_POST['submit'])
	{
	$myusername = $_POST['username']; 
	$mypassword = $_POST['password'];
	$myadmin = $_POST['admin'];// ok
		if($myusername && $mypassword && $myadmin)
		{
                $sql = mysql_query("select * from login");

					while($getrows = mysql_fetch_array($sql))
					{
					$dbuser = $getrows['Username'];
					$dbpass = $getrows['Password'];
					$dbrole = $getrows['Role'];
					}

					if(($myusername == $dbuser) && ($mypassword == $dbpass) && ($dbrole-->"Admin"))
					{
					header("location:Home.php");
					}

	                                else if(($myusername == $dbuser) && ($mypassword == $dbpass) && ($dbrole-->"Member"))
			
				        {
				        header("location:Home.php");
				        }


				else
				{
				echo "Login Failed......";
				}
					
			
		}
		
		
	else
		{
		echo "username and password failed";
		}
	}
	
?>

Re: Prob in login Page

Posted: Thu Mar 22, 2012 3:24 am
by social_experiment
I see a few issues but unless you give more details about the problem you are having i can't give advice

Prob in login.php page

Posted: Thu Mar 22, 2012 5:32 am
by GaneshPrasad
login.html page

Code: Select all

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<center>
<form action="Login.php" method="post">
<fieldset>
    <legend>Plese Enter your login Credentials:</legend>
	<h2>PlanMyDay</h2>
	Username:
	<input type="text" name="username">//username
	<br>
	Password:
	<input type="password" name="password">//password
	<br>
	SuperAdminOptions:
	<select name="admin">//select option
	  <option value="Admin">Admin</option>
	  <option value="Member">Member</option>
	</select>
	<br>
	<input type="submit" name="submit" value="Login">
</fieldset>
</form>
</center>
</body>
</html>
Login.php//login.html page navigate the login.php page

Code: Select all

<?php
include("connection.php");
      if($_POST['submit'])
	{
	$myusername = $_POST['username']; 
	$mypassword = $_POST['password'];
	$myadmin = $_POST['admin'];// ok
		if($myusername && $mypassword && $myadmin)
		{
                $sql = mysql_query("select * from login");

					while($getrows = mysql_fetch_array($sql))
					{
					$dbuser = $getrows['Username'];
					$dbpass = $getrows['Password'];
					$dbrole = $getrows['Role'];
					}

					if(($myusername == $dbuser) && ($mypassword == $dbpass) && ($dbrole-->"Admin"))
					{
					header("location:Home.php");
					}

	                                else if(($myusername == $dbuser) && ($mypassword == $dbpass) && ($dbrole-->"Member"))
			
				        {
				        header("location:Home.php");
				        }


				else
				{
				echo "Login Failed......";
				}
					
			
		}
		
		
	else
		{
		echo "username and password failed";
		}
	}
	
?>
connection.php

Code: Select all

<?php
mysql_connect("Localhost","root","");
mysql_select_db("planmyday");
?>
Here just see

Code: Select all

database name is----- planmyday
tablename is----------login
fields are-------------Id,     Username,    Password,    Role
                           PMD01    abc              abc            Admin
                           PMD02    xyz               xyz           Member
Actully what I want when the admin will enter username, password and select admin then move for admin home page
second thing when he will select member then move for member home page .

Re: Prob in login Page

Posted: Thu Mar 22, 2012 5:45 am
by social_experiment
GaneshPrasad wrote: when the admin will enter username, password and select admin then move for admin home page
Redirect on successful login;

Code: Select all

<?php
if(($myusername == $dbuser) && ($mypassword == $dbpass) && ($dbrole-->"Admin"))
{
header("location:Home.php");
}
?>
You have the idea correct but not the code

Code: Select all

<?php
if(($myusername == $dbuser) && ($mypassword == $dbpass) && ($dbrole == "Admin"))
{
header("location:Home.php");
}
?>
This snippet below could be better

Code: Select all

<?php
if($myusername && $mypassword && $myadmin)
?>
Maybe check if the values contain any data, correct type of data.

The second question i don't understand though. Also this is beyond the scope of this post but the code is lacking basic escaping of data and using what seems to be plain text passwords in the database. Both are issues to look at once the script is working