TY5-30 [WebX.0 CIAP (Component-1)]
TY5-30 [WebX.0 CIAP (Component-1)]
Class : TY5
Batch : B
Roll No: 30
PRN : 22UF16978IT087
<div>
<h1>Check Your SEM V Result</h1>
<input type="text" id="prnInput" placeholder="Enter PRN Number">
<button onclick="fetchResult()">Check Result</button>
</div>
<script src="script.js"></script>
</body>
</html>
Script.js
if (!prn) {
alert("⚠️ Please enter a PRN number.");
return;
}
try {
const response = await fetch(`http://localhost:5000/results/${prn}`);
const resultBox = document.getElementById('resultBox');
const marksTable = document.getElementById('marksTable');
if (!response.ok) {
alert("❌ Result not found!");
resultBox.style.display = 'none';
return;
}
// Populate Marks
if (data.marks && typeof data.marks === "object") {
Object.entries(data.marks).forEach(([subject, mark]) => {
const row = marksTable.insertRow();
row.insertCell(0).innerText = subject;
row.insertCell(1).innerText = mark;
});
} else {
const row = marksTable.insertRow();
row.insertCell(0).innerText = "No subjects found";
row.insertCell(1).innerText = "--";
}
resultBox.style.display = 'block';
} catch (error) {
alert("⚠️ Error fetching result. Please check your connection.");
console.error("Fetch Error:", error);
}
}
sever.js
const express = require('express');
const mongoose = require('mongoose');
const cors = require('cors');
// Middleware
app.use(cors());
app.use(express.json());
// MongoDB Connection
mongoose.connect('mongodb://127.0.0.1:27017/sakec_db', {
useNewUrlParser: true,
useUnifiedTopology: true
})
.then(() => console.log(" Connected to MongoDB"))
.catch(err => console.error(" MongoDB Connection Error:", err));
// Define Schema
const resultSchema = new mongoose.Schema({
prn: { type: String, required: true, unique: true },
name: String,
email: String,
class: String,
marks: Object
});
// Create Model
const Result = mongoose.model('Result', resultSchema);
// Start Server
app.listen(PORT, () => {
console.log(` Server running on http://localhost:${PORT}`);
});
Styles.css
body {
font-family: 'Arial', sans-serif;
background-color: #f4f4f4;
text-align: center;
margin: 0;
padding: 20px;
}
h1 {
color: #333;
margin-bottom: 20px;
}
input {
width: 300px;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 16px;
}
button {
padding: 10px 15px;
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
transition: 0.3s;
}
button:hover {
background-color: #0056b3;
}
.result-box {
background: white;
width: 50%;
margin: 20px auto;
padding: 20px;
border-radius: 10px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
display: none;
}
h2, h3 {
color: #444;
}
table {
width: 80%;
margin: 20px auto;
border-collapse: collapse;
background: white;
}
th, td {
padding: 10px;
border: 1px solid #ddd;
text-align: center;
}
th {
background-color: #007bff;
color: white;
}
td {
background-color: #f9f9f9;}
4. Output :
➢ Front Page
➢ Check
5. Establish Connection:
6. DataBase: