Prob in login Page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
GaneshPrasad
Forum Newbie
Posts: 5
Joined: Thu Mar 22, 2012 12:50 am

Prob in login Page

Post 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";
		}
	}
	
?>
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Prob in login Page

Post 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
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
GaneshPrasad
Forum Newbie
Posts: 5
Joined: Thu Mar 22, 2012 12:50 am

Prob in login.php page

Post 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 .
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Prob in login Page

Post 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
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply