Jump to content

Simple php login page


vardaloupas

Recommended Posts

Hello

I try to made a login page but i have problems....

 

login.html page

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
	<tr>
		<form name="form1" method="post" action="checklogin.php">
			<td>
				<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
					<tr>
						<td colspan="3"><strong>Member Login </strong></td>
					</tr>
						<tr>
							<td width="78">Username</td>
							<td width="6">:</td>
							<td width="294"><input name="myusername" type="text" id="myusername"></td>
						</tr>
						<tr>
							<td>Password</td>
							<td>:</td>
							<td><input name="mypassword" type="password" id="mypassword"></td>
						</tr>
						<tr>
            				<td width="78">Status</td>
            				<td width="6">:</td>
            				<td>
             					 <select name="mystatus">
               					 <option value="Admin">Admin</option>
              			 		 <option value="Technician">Technician</option>
               					 <option value="AirTrafficController">Air traffic controller</option>
             					 </select>
           					 </td>
						<tr>
							<td> </td>
							<td> </td>
						<td><input type="submit" name="Submit" value="Login"></td>
					</tr>
				</table>
			</td>
		</form>
	</tr>
</table>
</body>
</html>

 

 

 

AND check_login.php page

<?php
ob_start();
$host="localhost"; // Host name 
$username=""; // Mysql username 
$password=""; // Mysql password 
$db_name="ergasia2"; // Database name 
$tbl_name="EMPLOYEES"; // Table name
$status="";

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password", "$status")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// Define $myusername and $mypassword 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword'];
$status = $_POST['mystatus'];


if($count==1){
if ($_POST['mystatus'] == 'root') {
                  header("location:".admin.html);
             } 
elseif ($_POST['mystatus'] == 'vassilis'){
                  header("location:".controler.html);
              }
elseif ($_POST['mystatus'] == 'vassilis'){
			  header("location:".technician.html);
}

else {
echo "Wrong Username or Password";
}
}

ob_end_flush();
?>

 

The first problem is I can't connect with database but when I m trying to check with a script everything is ok....

 

<?php
$link = mysql_connect("localhost","root","123");
if(! $link)
        die("Could not connect to MySQL");
else
        print("Connected to MySQL server<P>");
$database = "ergasia2";
mysql_select_db($database)
        or die ("could not open $database: ".mysql_error() );
print "Opened database \"$database\"<P>";

mysql_close($link);
print "Everything works";
?>

 

 

The results of previous script.

 

Connected to MySQL server

Opened database "ergasia2"

 

Everything works

Link to comment
https://forums.phpfreaks.com/topic/225392-simple-php-login-page/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.