I need to get admin name and password .Then need to compare the user input with MySQL using php. If the database is validated I should log in him to next page. how to write php functions to access MySQL, after checking with database if the validations are OK. I should log-in him.
My html code for design:
<?php
?>
<!DOCTYPE HTML>
<head>
<title>Login Page</title>
<link rel="stylesheet" type="text/css" href="css/home.css">
<script src="js/home.js"> </script>
</head>
<body>
<form action="validate_login.php" method="post">
<div>
<div class="layout">
<div class="heading"></div>
<div class="img1"></div>
<div class="login">
<div class="logo"></div>
<div > <label class="AdminName">Admin Name</label> <input type="text" name="AdminName" value="AdminName" id="AdminName"/></div>
<div > <label class="Password">Password</label> <input type="password" name="Password" value="Password" id="Password" /></div>
<input type="button" button onclick='window.location="menu.php"' name="Login" id="login" value="LOGIN"/>
<input type="button" name="Login" id="cancel" value="cancel"/></form>
</div>
<div class="img2"></div>
</div>
</div>
</body>
My php code to access database:
<?php
// Grab User submitted information
$AdminName = $_POST["AdminName"];
$Password = $_POST["Password"];
// Connect to the database
$con = mysql_connect("localhost","admin","admin@123");
// Make sure we connected succesfully
if(! $con)
{
die('Connection Failed'.mysql_error());
}
// Select the database to use
mysql_select_db("admin_data",$con);
$result = mysql_query("SELECT AdminName, Password FROM admin_info WHERE AdminName = $AdminName");
$row = mysql_fetch_array($result);
if($row["AdminName"]==$AdminName && $row["Password"]==$Password)
echo"You are a validated user.";
else
echo"Sorry, your credentials are not valid, Please try again.";
?>