Full Stack
Full Stack
Problem Statement-5 Write a PHP program to create a database and a table using
Mysqli.
Source Code-
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "db2";
$conn = new mysqli($servername,
$username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn-
>connect_error);
}
$sql = "CREATE TABLE Student (
id INT(6) PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50)
)";
if ($conn->query($sql) === TRUE) {
echo "Table Student created successfully";
} else {
Name: Ritika Kumari Sub :Full Stack Dev Practical
Roll no: 2301300/48 Sub Code: PMC 101
Course: MCA sec A
OUTPUT
Name: Ritika Kumari Sub :Full Stack Dev Practical
Roll no: 2301300/48 Sub Code: PMC 101
Course: MCA sec A
<form method="post">
<label for="rollno">RollNo:</label>
<input type="number" name="rollno" required><br><br>
<label for="name">Name:</label>
<input type="text" name="name" required><br><br>
<label for="email">Email:</label>
<input type="email" name="email" required><br><br>
<label for="course">Course:</label>
<input type="text" name="course" required><br><br>
<?php
// Database connection
$dbHost = "localhost";
$dbUser = "root";
$dbPass = "";
Name: Ritika Kumari Sub :Full Stack Dev Practical
Roll no: 2301300/48 Sub Code: PMC 101
Course: MCA sec A
$dbName = "student";
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo"Student Record<br>";
if (isset($_POST['rollno'])) {
$rollno = $_POST["rollno"];
echo "RollNo: $rollno<br>";
}
if (isset($_POST['name'])) {
$name = $_POST["name"];
echo "Name: $name<br>";
}
if (isset($_POST["email"])) {
$email = $_POST["email"];
echo "Email: $email<br>";
}
if (isset($_POST["course"])) {
$course = $_POST["course"];
echo "Course: $course<br>";
$sql = "INSERT INTO students (rollno, name, email, course) VALUES ('$rollno',
'$name', '$email', '$course')";
}
$conn->close();
?>
</body>
</html>
Name: Ritika Kumari Sub :Full Stack Dev Practical
Roll no: 2301300/48 Sub Code: PMC 101
Course: MCA sec A
Output
Name: Ritika Kumari Sub :Full Stack Dev Practical
Roll no: 2301300/48 Sub Code: PMC 101
Course: MCA sec A
<?php
// Database connection
$dbHost = "localhost";
$dbUser = "root";
$dbPass = "";
Name: Ritika Kumari Sub :Full Stack Dev Practical
Roll no: 2301300/48 Sub Code: PMC 101
Course: MCA sec A
$dbName = "student";
$conn = new mysqli($dbHost, $dbUser, $dbPass, $dbName);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo"Student Record<br>";
if (isset($_POST['rollno'])) {
$rollno = $_POST["rollno"];
echo "RollNo: $rollno<br>";
}
if (isset($_POST['name'])) {
$name = $_POST["name"];
echo "Name: $name<br>";
}
if (isset($_POST["course"])) {
$course = $_POST["course"];
echo "Course: $course<br>";
$sql = "UPDATE students SET course='$course',rollno='$rollno' WHERE
name='$name'";
if ($conn->query($sql) === TRUE) {
echo "Course and RollNo information updated successfully!";
} else {
echo "Error updating course information: " . $conn->error;
}?>
</body>
</html>
Name: Ritika Kumari Sub :Full Stack Dev Practical
Roll no: 2301300/48 Sub Code: PMC 101
Course: MCA sec A
Output
Name: Ritika Kumari Sub :Full Stack Dev Practical
Roll no: 2301300/48 Sub Code: PMC 101
Course: MCA sec A
Source Code
<!DOCTYPE html>
<html lang="en">
<head>
<title>Customer Information</title>
</head>
<body>
<?php
$dbHost = "localhost";
$dbUser = "root";
$dbPass = "";
$dbName = "employee";
$conn = new mysqli($dbHost, $dbUser,
$dbPass, $dbName);
if ($conn->connect_error) {
die("Connection failed: " . $conn-
>connect_error);
}
$sql = "SELECT c_no, c_name,
item_purchased, mob_no FROM
customer";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
Name: Ritika Kumari Sub :Full Stack Dev Practical
Roll no: 2301300/48 Sub Code: PMC 101
Course: MCA sec A
echo "<table>";
echo "<tr><th>Customer
Number</th><th>Customer
Name</th><th>Item
Purchased</th><th>Mobile
Number</th></tr>";
while($row = $result->fetch_assoc()) {
echo
"<tr><td>".$row["c_no"]."</td><td>".$ro
w["c_name"]."</td><td>".$row["item_purc
hased"]."</td><td>".$row["mob_no"]."</td
></tr>";
}
echo "</table>";
}
else {
echo "0 results";
}
$conn->close();
?>
Name: Ritika Kumari Sub :Full Stack Dev Practical
Roll no: 2301300/48 Sub Code: PMC 101
Course: MCA sec A
Output
Name: Ritika Kumari Sub :Full Stack Dev Practical
Roll no: 2301300/48 Sub Code: PMC 101
Course: MCA sec A
Problem Statement9- Write a PHP program to upload an image and save in the
database.
Objective: To understand how to upload an image and save in the database.
Source Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Image Upload</title>
</head>
<body>
<form action="" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="image" id="image"><br>
<input type="submit" value="Upload Image" name="submit"><br><br>
</form>
<?php
$dbHost = "localhost";
$dbUser = "root";
$dbPass = "";
$dbName = "student";
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if (move_uploaded_file($_FILES["image"]["tmp_name"], $targetFile)) {
$imageName = basename($_FILES["image"]["name"]);
$sql = "INSERT INTO images (image_name) VALUES ('$imageName')";
</body>
</html>
Name: Ritika Kumari Sub :Full Stack Dev Practical
Roll no: 2301300/48 Sub Code: PMC 101
Course: MCA sec A
Output
Name: Ritika Kumari Sub :Full Stack Dev Practical
Roll no: 2301300/48 Sub Code: PMC 101
Course: MCA sec A
Problem Statement10- Write a PHP program to set a cookie on the web page for 7
days and display the message whether the cookie is set or not.
Source Code
<!DOCTYPE html>
<?php
$cookie_name = "Ritika";
$cookie_value = "19";
setcookie($cookie_name, $cookie_value,
time() + (7 * 24 * 60 * 60), "/"); // 86400 =
1 day
?>
<html>
<body>
<?php
if(!isset($_COOKIE[$cookie_name])) {
echo "Cookie named '" . $cookie_name .
"' is not set!";
} else {
echo "Cookie '" . $cookie_name . "' is
set!<br>";
echo "Value is: " .
$_COOKIE[$cookie_name];
}
?> </body></html>
Name: Ritika Kumari Sub :Full Stack Dev Practical
Roll no: 2301300/48 Sub Code: PMC 101
Course: MCA sec A
Output
Name: Ritika Kumari Sub :Full Stack Dev Practical
Roll no: 2301300/48 Sub Code: PMC 101
Course: MCA sec A
Problem Statement 11- Write a PHP program to create a session, if the user is logged
in display the message “user logged in” if the session ends display “user logged out”.
Output
Name: Ritika Kumari Sub :Full Stack Dev Practical
Roll no: 2301300/48 Sub Code: PMC 101
Course: MCA sec A
Source Code
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Student Registration Form</title>
</head>
<body>
<script>
function isFirstCharacterUppercase(str) {
if (str.length === 0) {
return false;
}
Output
Name: Ritika Kumari Sub :Full Stack Dev Practical
Roll no: 2301300/48 Sub Code: PMC 101
Course: MCA sec A
Problem Statement13- Write a JavaScript program to apply all mouse events on any
element.
Source Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mouse Events Example</title>
<style>
#targetElement {
width: 200px;
height: 100px;
background-color: lightblue;
text-align: center;
line-height: 100px;
cursor: pointer;
}
</style>
</head>
<body>
<script>
var targetElement = document.getElementById('targetElement');
function handleMouseDown() {
document.write('Mouse Down');
}
Name: Ritika Kumari Sub :Full Stack Dev Practical
Roll no: 2301300/48 Sub Code: PMC 101
Course: MCA sec A
function handleMouseUp() {
document.write('Mouse Up');
}
function handleMouseMove() {
document.write('Mouse Move');
}
function handleMouseOver() {
document.write('Mouse Over');
}
function handleMouseOut() {
document.write('Mouse Out');
}
targetElement.addEventListener('mousedown', handleMouseDown);
targetElement.addEventListener('mouseup', handleMouseUp);
targetElement.addEventListener('mousemove', handleMouseMove);
targetElement.addEventListener('mouseover', handleMouseOver);
targetElement.addEventListener('mouseout', handleMouseOut);
</script>
</body>
</html>
Name: Ritika Kumari Sub :Full Stack Dev Practical
Roll no: 2301300/48 Sub Code: PMC 101
Course: MCA sec A
Output
Name: Ritika Kumari Sub :Full Stack Dev Practical
Roll no: 2301300/48 Sub Code: PMC 101
Course: MCA sec A
Source Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Background Color Changer</title>
</head>
<body>
<script>
function changeBackgroundColor(event) {
// Get the selected color value from the color picker input
var selectedColor = event.target.value;
</body>
</html>
Name: Ritika Kumari Sub :Full Stack Dev Practical
Roll no: 2301300/48 Sub Code: PMC 101
Course: MCA sec A
Output
Name: Ritika Kumari Sub :Full Stack Dev Practical
Roll no: 2301300/48 Sub Code: PMC 101
Course: MCA sec A
Problem Statement15- Create a student registration form with the following fields
• Username: must contain university name as a pattern
• Password: should be alphanumeric
• Phone number: starts with the digits {6,7,8,9}
• Email id: valid email address
And validate the form using javaScript as the above-mentioned
conditions.
Source Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Student Registration Form</title>
<style>
.error {
color: red;
}
</style>
</head>
<body>
<br>
<script>
function validateForm() {
document.getElementById("usernameError").textContent = "";
document.getElementById("passwordError").textContent = "";
document.getElementById("phoneNumberError").textContent = "";
document.getElementById("emailError").textContent = "";
var username = document.getElementById("username").value;
if (!username.includes("GEHU")) {
document.getElementById("usernameError").textContent = "Username must
contain GEHU";
return false;
}
var password = document.getElementById("password").value;
if (!/^[a-zA-Z0-9]+$/.test(password)) {
document.getElementById("passwordError").textContent = "Password should be
alphanumeric";
return false;
}
var phoneNumber = document.getElementById("phoneNumber").value;
if (!/^[6-9]\d{9}$/.test(phoneNumber)) {
document.getElementById("phoneNumberError").textContent = "Phone Number
should start with 6, 7, 8, or 9";
return false;
Name: Ritika Kumari Sub :Full Stack Dev Practical
Roll no: 2301300/48 Sub Code: PMC 101
Course: MCA sec A
}
var email = document.getElementById("email").value;
if (!isValidEmail(email)) {
document.getElementById("emailError").textContent = "Invalid email address";
return false;
}
return true;
}
function isValidEmail(email) {
var emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}
</script>
</body>
</html>
Name: Ritika Kumari Sub :Full Stack Dev Practical
Roll no: 2301300/48 Sub Code: PMC 101
Course: MCA sec A
Output
Name: Ritika Kumari Sub :Full Stack Dev Practical
Roll no: 2301300/48 Sub Code: PMC 101
Course: MCA sec A
Problem Statement16- Write a JavaScript program to display the current date and
time in the following format
Date: date/month/year
Time: hour/minute/second
Objective: To understand how to use Date Object
Source Code
<!DOCTYPE html>
<html>
<head>
<title>Current Date and Time</title>
<script>
function displayDateTime() {
Output