Need some help with the help with the SQL and all questions in the image attache
ID: 3821154 • Letter: N
Question
Need some help with the help with the SQL and all questions in the image attached..
here is what i have so far..
<?php
// initialize variables
$email = "";
$password = "";
$emailMessage = '';
$emailClass = '';
$passwordMessage = '';
$passwordClass = '';
$emailMessage = '';
$emailClass = '';
$passwordMessage = '';
$passwordClass = '';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chapter 13</title>
<!-- Bootstrap core CSS -->
<link href="bootstrap3_defaultTheme/dist/css/bootstrap.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="chapter13-project01.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="bootstrap3_defaultTheme/assets/js/html5shiv.js"></script>
<script src="bootstrap3_defaultTheme/assets/js/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-3">
</div>
<div class="col-md-6">
<div id="login">
<div class="page-header">
<h2>Login</h2>
</div>
<form role="form" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<div class="form-group <?php echo $emailClass; ?>">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" name="email" value="<?php echo $email; ?>">
<p class="help-block"><?php echo $emailMessage; ?></p>
</div>
<div class="form-group <?php echo $passwordClass; ?>">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" name="password" value="<?php echo $password; ?>>
<p class="help-block"><?php echo $passwordMessage; ?></p>
</div>
<div class="form-group">
<label for="exampleInputFile">Server</label>
<select name="server" class="form-control">
<?php
for ($i = 1; $i < 6; $i++) {
echo '<option>Server ' . $i . '</option>';
}
?>
</select>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
<div class="col-md-3">
</div>
</div>
</div> <!-- end container -->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="bootstrap3_defaultTheme/assets/js/jquery.js"></script>
<script src="bootstrap3_defaultTheme/dist/js/bootstrap.min.js"></script>
</body>
</html>
Explanation / Answer
index.php
<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<title>RGUKT Examcell-Internal DB</title>
<link rel="stylesheet" href="loginstyle.css">
</head>
<body>
<div align="center" ><img src="dlogo.jpg"></img></div>
<div class="wrapper" align="center">
<div class="container" >
<h1>Welcome ecell</h1>
<form class="form" name="loginform" method="POST" action="login.php">
<input type="text" placeholder="Username" name="id" id="id" required>
<input type="password" placeholder="Password" name="password" id="password" required>
<button type="submit" id="login-button">Login</button>
</form>
</div>
</div>
</body>
</html>
login.php
<?php
session_start();
if(count($_POST)>0)
{
include("db_config.php");
$userid=mysql_real_escape_string($_POST["id"]);
$pass=mysql_real_escape_string($_POST["password"]);
$result = mysql_query("SELECT * FROM admin WHERE UserID='$userid' and Password = '$pass'");
$row = mysql_fetch_array($result);
if(is_array($row))
{
$_SESSION["id"] = $row['UserID'];
header("Location:external.php");
}
else
{
header("Location:fail.php");
}
}
else
{
header("Location:fail.php");
}
?>
fail.php
<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="dashboard/assets/css/loginstyle.css">
</head>
<body>
<div align="center" ><img src="dashboard/assets/img/RGUKT1.JPG"></img></div>
<div class="wrapper" align="center">
<div class="container" >
<h4>Welcome ecell !. Invalid login Try again</h4>
<form class="form" name="loginform" method="POST" action="login.php">
<input type="text" placeholder="Username" name="id" id="id" required>
<input type="password" placeholder="Password" name="password" id="password" required>
<button type="submit" id="login-button">Login</button>
</form>
</div>
</div>
</body>
</html>
external.php :
<?php
session_start();
if(!(($_SESSION["id"])&&($_SESSION["type"]=='L3')))
{
header("Location:index.php");
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Example</title>
</head>
<body>
<div id="wrapper">
<nav class="navbar navbar-default navbar-cls-top " role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".sidebar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#"><?php echo $adminname; ?></a>
</div>
<div>Welcome<b> <?php echo "User"; ?></b> <a href="../logout.php" class="btn btn-danger square-btn-adjust">Logout</a> </div>
</body>
</html
Logout.php:
<?php
session_start();
unset($_SESSION["id"]);
header("Location:index.php");
?>
Dbconfig.php:
<?php
$connect=mysql_connect("localhost","root","");
if(!$connect)
{
echo "No Connection";
}
mysql_select_db("dbname");
?>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.