Professional Documents
Culture Documents
CSE3002 Lab9 20BCE1912
CSE3002 Lab9 20BCE1912
Name: Madhumitha R
Reg.No.: 20BCE1912
1. Develop the website for insurance company for their customers using HTML, PHP,
MySQL
c) After sign in, get the policy number to display the policy details
Login.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta
name="viewport" content="width=device-width, initial-scale=1.0">
<title>PolicyBazzar</title>
<link rel="stylesheet" href="style.css">
</head>
<?php
session_start();
?>
<body>
<form action="login.php" method="post">
<table>
<tr colspan="2">
<td><h1 class="xd">LOGIN</h1></td>
<?php
if (!array_key_exists('login_error', $_SESSION) or
$_SESSION['login_error'] == false){
echo "";
}else{
echo '<div class="error">email/password does not match</div>';
}
?>
</tr>
<tr>
<td><label for="email"><h3>Email:</h3></label></td> <td><input
class="inpbox" type="email" name="email" id="email" color="black"
required></td>
</tr>
<tr>
<td><label for="password"><h3>Password:</h3></label></td>
<td><input class="inpbox" type="password" name="password"
id="password" color="black" required></td>
</tr>
<tr>
<td colspan="2"><input type="submit" class = "xd" id="button"
value="Submit"></td>
</tr>
<tr>
<td><a href="signup.php">Dont Have an account? SignUp</a></td>
</tr>
</table>
</form>
</body>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
require "conn.php";
$sqlq = 'SELECT email, pass FROM users';
$result = mysqli_query($conn, $sqlq);
print_r($result);
$rows = mysqli_num_rows($result);
#echo "<p>$rows</p>";
if ($rows > 0){
$ee = $_POST["email"];
$pp = $_POST["password"];
while ($row = mysqli_fetch_assoc($result)){
$re = $row["email"];
$rp = $row["pass"];
#echo "<p>$re $rp $ee $pp</p><br>";
if ($re == $ee and $rp == $pp){
$_SESSION['email'] = $re;
$_SESSION['login_error'] = false;
header("Location: home.php");
}
}
}
$_SESSION['login_error'] = true;
mysqli_close($conn);
}
?>
</html>
Signup.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta
name="viewport" content="width=device-width, initial-scale=1.0">
<title>Signup</title>
<link rel="stylesheet" href="style.css">
</head>
<?php
session_start();
?>
<body>
<form action = "signup.php" method = "post">
<?php
if (!array_key_exists('insertion_error', $_SESSION) or
$_SESSION['insertion_error'] == false){
echo "";
}else{
echo '<div class="alert alert-danger" role="alert">email already
registered</div>';
}
?>
<table>
<tr colspan="2">
<td><h1 class="xd">LOGIN</h1></td>
<?php
if (!array_key_exists('login_error', $_SESSION) or
$_SESSION['login_error'] == false){
echo "";
}else{
echo '<div class="" role="alert">email/password does not
match</div>';
}
?>
</tr>
<tr>
<td><label for="fname"><h3>First Name:</h3></label></td> <td><input
class="inpbox" type="textbox" name="fname" id="fname" required></td>
</tr>
<tr>
<td><label for="lname"><h3>Last Name:</h3></label></td> <td><input
class="inpbox" type="textbox" name="lname" id="lname" required></td>
</tr>
<tr>
<td><label for="email"><h3>Email:</h3></label></td>
<td><input class="inpbox" type="email" name="emm" id="emm"
required></td>
</tr>
<tr>
<td><label for="pss"><h3>Password:</h3></label></td> <td><input
class="inpbox" type="password" name="pss" id="pss" required></td>
</tr>
<tr>
<td colspan="2"><input type="submit" class = "xd" id="button"
value="Submit"></td>
</tr>
</table>
</form>
</body>
<?php
require "conn.php";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$f = $_POST["fname"];
$l = $_POST["lname"];
$e = $_POST["emm"];
$p = $_POST["pss"];
#echo "<p>$f $l $e $p</p><br>";
$sql = "INSERT INTO `users` VALUES ('$f', '$l', '$e', '$p')"; #echo
"<p>$sqlq</p>";
$result = mysqli_query($conn, $sql);
if ($result){
$_SESSION['insertion_error'] = false;
}else{
$_SESSION['insertion_error'] = true;
}
}
?>
</html>
Home.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta
name="viewport" content="width=device-width, initial-scale=1.0">
<title>Signup</title>
<link rel="stylesheet" href="style.css">
</head>
<?php
session_start();
require "conn.php";
$email = $_SESSION['email'];
$sql = "SELECT policynumber FROM `policy` WHERE email = '$email'";
$result = mysqli_query($conn, $sql);
$rows = mysqli_num_rows($result);
if ($rows > 0){
while ($row = mysqli_fetch_assoc($result)){
$policynumber = $row["policynumber"];
}
}
$sql = "SELECT fname,lname FROM `users` WHERE email='$email'; ";
$result = mysqli_query($conn, $sql);
$rows = mysqli_num_rows($result);
if ($rows > 0){
while ($row = mysqli_fetch_assoc($result)){
$_SESSION['fname'] = $row["fname"];
$_SESSION['lname'] = $row["lname"];
}
}
echo "<body>
<div>
<table>
<tr>
<td><label for='fname'><h3>First Name:</h3></label></td>
<td><h3>".$_SESSION['fname']."<h3></td> </tr>
<tr>
<td><label for='lname'><h3>Last Name:</h3></label></td>
<td><h3>".$_SESSION['lname']."<h3></td> </tr>
<tr>
<td><label for='email'><h3>Email:</h3></label></td>
<td><h3>".$_SESSION['email']."<h3></td> </tr>
<tr>
<td><label for='pss'><h3>Policy Number:</h3></label></td>
<td><h3>$policynumber<h3></td>
</tr>
</table>
</div>
</body>
</html>";
?>
Conn.php
<?php
$dbhost = "127.0.0.1";
$dbuser = "root";
$dbpass = "";
$dbname = "policybazaar";
//connection to database
$conn = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname); if
(!$conn){
die("Database connection failed");
}
?>
Output:
2. Use PHP’s built-in mail() function to send an email message from your email id to your
own email id.
The subject field should have Howdy.
The message body should contain
How do you do? My dear friend!
With love, Your Register No and Name.
CODE:
<?php
$to = "madhumitha.2020@vitstudent.ac.in"; $subject = "Howdy";
$message = "
<html>
<head>
<title>Howdy</title>
</head>
<body>
<h4>How do you do? My dear friend!</h4> <h2>With love</h2>
<h4>Madhumitha R</h4>
<h4>20BCE1912</h4>
</body>
</html>
";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <madhumitha.2020@vitstudent.ac.in>' . "\r\n";
$headers .= 'Cc: madhumitharajagopal0530@gmail.com' . "\r\n";
if(mail($to,$subject,$message, $headers))
{
echo "Mail Sent Success.";
} else {
echo "Mail sent unsuccess.";
}
?>
OUTPUT: