Develop a simple Web application that generates, from the database shown in the
ID: 3863191 • Letter: D
Question
Develop a simple Web application that generates, from the database shown in the appendix, a simplified student transcript given his user name and password. The site consists of three (3) modules, you name: login.php, register.php and generate.php In the login.php you just validate that the student has entered a username and a password. If valid redirect the user to the generate.php by clicking on the link Generate Report Otherwise notify the user that the username and password are required. 2. n the generate.php, do the following Check whether the student is registered (use query Q1). If not, direct the student to register.php by clicking on Registration Page Otherwise: Generate the transcript using query Q2 Format the output in a table as shown in Figure 2. Compute the average gpa from the database, using the query Q3 Update the student's gpa n the table students setting it with the grade defined in query Q3 Query Q1: check (with un an pw) if the student who attempts to login is registered Query Q2: generate the transcript for the logged student from transcript where un xxx (where 'xxx' is the username of the logged student and grade is the output of query) Query Q4: update the logged student setting the gpa to grade login.phpExplanation / Answer
config.php
<?php
define('DB_SERVER', 'localhost:3036');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', 'rootpassword');
define('DB_DATABASE', 'labtest');
$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
?>
login.php
<?php
include("config.php");
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST") {
$myusername = mysqli_real_escape_string($db,$_POST['username']);
$mypassword = mysqli_real_escape_string($db,$_POST['password']);
$sql = "SELECT id FROM students WHERE un = '$myusername' and pw = '$mypassword'";
$result = mysqli_query($db,$sql);
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
$active = $row['active'];
$count = mysqli_num_rows($result);
// result matched $myusername and $mypassword then table row must be 1 row
if($count == 1) {
session_register("myusername");
$_SESSION['login_user'] = $myusername;
header("location: generate.php");
}else {
$error = "Your Login Name or Password is invalid";
header("location: register.php");
}
}
?>
<html>
<head>
<title>Login Page</title>
<style type = "text/css">
body {
font-family:Arial, Helvetica, sans-serif;
font-size:14px;
}
label {
font-weight:bold;
width:100px;
font-size:14px;
}
.box {
border:#666666 solid 1px;
}
</style>
</head>
<body bgcolor = "#FFFFFF">
<div align = "center">
<div align = "left">
<div><b>Login</b></div>
<div>
<form action = "" method = "post">
<label>UserName :</label><input type = "text" name = "username" class = "box"/><br /><br />
<label>Password :</label><input type = "password" name = "password" class = "box" /><br/><br />
<input type = "submit" value = " Submit "/><br />
</form>
<div><?php echo $error; ?></div>
</div>
</div>
</div>
</body>
</html>
welcome.php
<?php
include('session.php');
?>
<html">
<head>
<title>Welcome </title>
</head>
<body>
<h1>Welcome <?php echo $login_session; ?></h1>
<h2><a href="generate.php">Generate Report</a></h2>
</body>
</html>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.