School Login Upload Fetch Project

=============== Register========================
<html>
<body> 
<form action="uploads.php" method="post" >
<p>First Name:<input type="text" name="fname" required= "required">Last Name:<input type="text" name="lname" required= "required"></p>
<p>Email:<input type="email" name="email" required= "required"></p>
<p>Password:<input type="password" name="password" required= "required" >
<p>Date of Birth:<input type="date" name="dob" required= "required" >
<p><input type="submit" name="submit"></p>
</form>
</body>

</html>
================================Connect===================
<?php
$connection = mysqli_connect('localhost', 'devika', 'devika');
if (!$connection){
    die("Database Connection Failed" . mysqli_error($connection));
}
$select_db = mysqli_select_db($connection, 'school');
if (!$select_db){
    die("Database Selection Failed" . mysqli_error($connection));
}

?>
===============================Login===================
<html>
<body>   
<form action="session.php" method="post" >
<p>Email:<input type="email" name="email" required= "required"></p>
<p>Password:<input type="password" name="password" required= "required" >

<p><input type="submit" name="submit"></p>
</form>

<p><u><a href="http://localhost/school/register.php">Create an Account</a></u></p>
</body>

</html>
===================Session===============================
<?php  //Start the Session
session_start();
 require('connect.php');
//3. If the form is submitted or not.
//3.1 If the form is submitted
if (isset($_POST['email']) and isset($_POST['password'])){
//3.1.1 Assigning posted values to variables.
$username = $_POST['email'];
$password = $_POST['password'];
//3.1.2 Checking the values are existing in the database or not
$query = "SELECT * FROM `register` WHERE email='$username' and password='$password'";

$result = mysqli_query($connection, $query) or die(mysqli_error($connection));
$count = mysqli_num_rows($result);
//$row = mysql_fetch_array($result);
$count =1;
//3.1.2 If the posted values are equal to the database values, then session will be created for the user.
if ($count == 1){
$_SESSION['username'] = $username;
}else{
//3.1.3 If the login credentials doesn't match, he will be shown with an error message.
$fmsg = "Invalid Login Credentials.";
echo $fmsg;
}
}
//3.1.4 if the user is logged in Greets the user with message
if (isset($_SESSION['username']))
{
$username = $_SESSION['username'];
echo "Hai " . $username . "";
echo "This is the Members Area";

echo "<a href='logout.php'>Logout</a>";
include 'studentform.php';
}else{}
//3.2 When the user visits the page first time, simple login form will be displayed.
?>
=============================StudentForm=======================
<html>
<body>   
<form action="uploads.php" method="post" enctype="multipart/form-data" >

<p>First Name:<input type="text" name="fname" required= "required">Last Name:<input type="text" name="lname" required= "required"></p>
<p>Roll No:<input type="text" name="roll" required= "required"></p>
<p>Class:<input type="text" name="class" required= "required" >
<p>Date of Birth:<input type="date" name="dob" required= "required" >
<p>Father Name:<input type="text" name="faname" required= "required">Mother Name:<input type="text" name="moname" required= "required"></p>
<p>Address:<input type="text" name="address" required= "required" >
<p>Phone:<input type="text" name="phone" required= "required" >
<p>Marks:<input type="text" name="marks" required= "required" >
<p>Status:<input type="text" name="status" required= "required" >
<p><input type="file" name="fileToUpload" value="Upload Image" id="fileToUpload">
<p><input type="submit" name="submit"></p>


</form>
</body>

</html>
=========================Uploads==========================
<?php

$firstname = $_POST['fname'];
$lastname = $_POST['lname'];
$rollno = $_POST['roll'];
$class = $_POST['class'];
$dob = $_POST['dob'];
$fathername = $_POST['faname'];
$mothername = $_POST['moname'];
$houseadd = $_POST['address'];
$contact = $_POST['phone'];
$marksheet = $_POST['marks'];
$status = $_POST['status'];


$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
    $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
    if($check !== false) {
        echo "File is an image - " . $check["mime"] . ".";
        $uploadOk = 1;
    } else {
        echo "File is not an image.";
        $uploadOk = 0;
    }
}
// Check if file already exists
if (file_exists($target_file)) {
    echo "Sorry, file already exists.";
    $uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
    echo "Sorry, your file is too large.";
    $uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
    echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
    $uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
    echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
    if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
        $servername = "localhost";
$username = "devika";
$password = "devika";
$dbname = "school";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);

$sql = "INSERT INTO studentdata (firstname, lastname, rollno,class,dateofbirth,fathername,mothername,address,phone,marks,status,image)
VALUES ('$firstname', '$lastname', '$rollno','$class','$dob','$fathername','$mothername','$houseadd','$contact','$marksheet','$status','$target_file')";

if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();

    } else {
        echo "Sorry, there was an error uploading your file.";
    }
}

include 'fetch.php';
?>
===============================Fetch======================
<?php
$con= mysqli_connect("localhost","devika","devika","school");

if(mysqli_connect_errno())
{
echo "Failed to connect " . mysqli_connect_error();
}

$sql="SELECT * FROM studentdata";

if ($result = mysqli_query($con,$sql))
{
?>
<table border= '1'>
<tr><td>First Name</td><td>Last Name</td><td>Roll No</td><td>Class</td><td>Date of Birth</td><td>Father Name</td><td>Mother Name</td><td>Address</td><td>Phone</td><td>Marks</td><td>Status</td><td>Image</td></tr>
<?php  
while ($row=mysqli_fetch_row($result))
{
$firstname=$row[0];
$lastname=$row[1];
$rollno=$row[2];
$class=$row[3];
$dateofbirth=$row[4];
$fathername=$row[5];
$mothername=$row[6];
$address=$row[7];
$phone=$row[8];
$email=$row[9];
$password=$row[10];
$image_path=$row[11];
$image_path=$row[12];
?>
<tr>
<td><?php echo $firstname;?></td>
<td><?php echo $lastname;?></td>

<td><?php echo $rollno;?></td>
<td><?php echo $class;?></td>

<td><?php echo $dateofbirth;?></td>
<td><?php echo $fathername;?></td>

<td><?php echo $mothername;?></td>
<td><?php echo $address;?></td>

<td><?php echo $phone;?></td>
<td><?php echo $marks;?></td>

<td><?php echo $status;?></td>

<td><img src = '<?php echo $image_path;?>' width='100' height= '100'/></td>
</tr></br>

<?php
}
// Free result set
mysqli_free_result($result);
?>
</table>
<?php
}
mysqli_close($con);
?>

<html>
<body>   

<form action="" method="post" >

<p>Enter Roll No:<input type="text" name="roll" required= "required"></p>

</form>
</body>

</html>
==============================Logout=======================
<?php
session_start();
session_destroy();
header('Location: login.php');
?>

Google SignIn App Code

<!Doctype html>

<head><title>Google SignIn</title>

<meta name="google-signin-client_id" content="428136239793-1q9iqu2uabg28khtrj2ksfdrjsnkf1af.apps.googleusercontent.com">
<script src="https://apis.google.com/js/platform.js" async defer></script>


<script src=" "></script>


<!-- Latest compiled and minified CSS -->
<Style>
.g-signin2{

margin-left:500px;

margin-top:200px;
}
.data{display:none;}

</style></head>

<body>
<div class="g-signin2" data-onsuccess="onSignIn"></div>
<div class="data">
<p>Profile Details</p>
<img id="pic" class="img-circle" width="100" height="100"/>
<p>Email Address</p><p id="email" class="alert alert-danger"</p>
<button onclick="signOut()" class="btn btn-danger">SignOut</button></div>


</body>
</html>







=========================script.js========================



function onSignIn(googleUser)
{
var profile= googleUser.getBasicProfile();
$(".g-signin2").css("display","none");
$(".data").css("display","block");
$("#pic").attr('src',profile.getImageUrl());
$("#email").text(profile.getEmail());

}



function signOut(){

var auth2 = gapi.auth2.getAuthInstance();
auth2.signOut().then(function(){

alert ("You have successfully signed out");
$(".g-signin2").css("display","block");
$(".data").css("display","none");

});


}