Lab Programs- 16-20
Lab Programs- 16-20
echo "<h2> PHP script to Show the Functionality of Date and Time Functions:
</h2>";
?>
Lab Program 17
Write a PHP Program to Upload a File.
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title>PHP File Upload</title>
</head>
<body>
<?php
if (isset($_SESSION['message'])) {
echo '<p><b>' . $_SESSION['message'] . '</b></p>';
if (isset($_SESSION['uploadedFilePath'])) {
echo '<p>Click to view the file: <a href="' .
$_SESSION['uploadedFilePath'] . '" target="_blank">View Uploaded
File</a></p>';
}
unset($_SESSION['message']);
unset($_SESSION['uploadedFilePath']);
}
?>
</body>
</html>
<?php
session_start();
if (move_uploaded_file($file['tmp_name'], $path)) {
$_SESSION['message'] = '✅ File uploaded successfully.';
$_SESSION['uploadedFilePath'] = $path;
} else {
$_SESSION['message'] = '❌ Failed to move uploaded file.';
}
} else {
$_SESSION['message'] = '❌ Upload failed or invalid file type.';
}
} else {
$_SESSION['message'] = '❌ No file uploaded.';
}
header('Location: LP17.php');
exit();
Lab Program 18
Write a PHP Script to Implement Database Creation.
<?php
$servername = "localhost";
$username = "root";
$password = ""; // Leave this empty for XAMPP default
$dbname = "new_database";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("❌ Connection failed: " . $conn->connect_error);
}
// Create database
$sql = "CREATE DATABASE $dbname";
if ($conn->query($sql) === TRUE) {
echo "✅ Database '$dbname' created successfully";
} else {
echo "❌ Error creating database: " . $conn->error;
}
// Close connection
$conn->close();
?>
http://localhost/phpmyadmin
Lab Program 19
Write a PHP Script to Create a Table.
<?php
// Database credentials
$servername = "localhost"; // Server name
$username = "root"; // MySQL username (default for XAMPP is 'root')
$password = ""; // MySQL password (default for XAMPP is empty)
$dbname = "new_database"; // The database where the table will be created
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("❌ Connection failed: " . $conn->connect_error);
}
echo "<h2> PHP Program to Design a College Admission Form Using MySQL
Database: </h2>";
// Database credentials
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "college_admission";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("❌ Connection failed: " . $conn->connect_error);
}
// Prepare the SQL query to insert form data into the database
$sql_insert = "INSERT INTO admission_form (first_name, last_name, email,
phone_number, course, gender, date_of_birth)
VALUES ('$first_name', '$last_name', '$email',
'$phone_number', '$course', '$gender', '$dob')";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>College Admission Form</title>
</head>
<body>
<h2>College Admission Form</h2>
<form action="" method="POST">
<label for="first_name">First Name:</label><br>
<input type="text" id="first_name" name="first_name" required><br><br>
<label for="course">Course:</label><br>
<input type="text" id="course" name="course"><br><br>
<label for="gender">Gender:</label><br>
<select id="gender" name="gender">
<option value="Male">Male</option>
<option value="Female">Female</option>
</select><br><br>
<?php
// Close connection
$conn->close();
?>