OSP RECORD 1 (8)
OSP RECORD 1 (8)
APPLICATIONS
“OPEN SOURCE PROGRAMMING lAb”
REG. NO :
SEMESTER-I
November – 2024
PERAMBALUR-621 212
DEPARTMENT OF COMPUTER APPLICATIONS
SRINIVASAN COLLEGE OF ARTS & SCIENCE
PERAMBALUR-621 212
CERTIFICATE
This is to certify that the bonafide record of the work done in the
computer laboratory during the academic year 2024-2025.
SUBMITTED BY
NAME : ________________________
REG.NO : ________________________
CLASS : ________________________
TITLE / SUB.CODE : ________________________
SEMESTER : ______________________
1. 2.
CONTENTS
PAGE REMARKS/
EX.NO DATE LIST OF PROGRAMS
NO. SIGNATURE
Students marklist preparation using control
statement and display the result in tabular
01
format.
Aim:
To develop a server side PHP program to display the marks, total, grade of a student in
tabular format by accepting user inputs for name, R.no. and marks in the HTML forms.
Procedure:
Step-1: To start and open the notepad and write the HTML program.
Step-2: Declare and define the method to using the POST() method and link the PHP file which
Step-5: Open the notepad and the write the PHP program.
Step-6: Declare and define the POST() method and link the HTML file which saved under
<tr>
<td><h3>student name:</h3></td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td><h3>student reg:</h3></td>
<td><input type="number" name="regno"></td>
</tr>
<tr>
<td><h3>mark1</h3></td>
<td><input type="number" name="m1"></td>
</tr>
<tr>
<td><h3>mark2</h3></td>
<td><input type="number" name="m2"></td>
</tr>
<tr>
<td><h3>mark3</h3></td>
<td><input type="number" name="m3"></td>
</tr>
</table>
<input type="submit" value="submit">
</center>
</form>
</body>
// stu1.php
<?php
$stuname=$_POST["name"];
$regno=$_POST["regno"];
$m1=$_POST["m1"];
$m2=$_POST["m2"];
$m3=$_POST["m3"];
$tot=$m1+$m2+$m3;
$avg=$tot/3;
if($avg>80)
{
$grade="distinion";
}
elseif($avg>70)
{
$grade="grade1";
}
elseif($avg>60){
$grade="grade2";}
elseif($avg>50)
{
$grade="pass";
}
else
{
$grade="fail";
}
echo"
<html>
<body>
<center>
<h1>student marksheet</h1>
<table border=1>
<tr>
<td><p>student name</p></td>
<td>$stuname</td>
</tr>
<tr>
<td><p>student regno</p></td>
<td>$regno</td>
</tr>
<tr>
<td><p>mark1</p></td>
<td>$m1</td>
</tr>
<tr>
<td><p>mark2</p></td>
<td>$m2</td>
</tr>
<tr>
<td><p>mark3</p></td>
<td>$m3</td>
</tr>
<tr>
<td><p>total</p></td>
<td>$tot</td>
</tr>
<tr>
<td><p>percentage</p></td>
<td>$avg</td>
</tr>
</table>
</center>
</body>
</html>"
?>
OUTPUT
EX NO:02
DATE:
SHOPPING CART
Aim:
To develop a PHP program to adds products that are selected form a web page to a
shopping cart.
Procedure:
Step-1: To start and open the notepad and write the HTML program.
Step-2: Declare and define the method to using the POST() method and link the PHP file which
Step-5: Open the notepad and the write the PHP program.
Step-6: Declare and define the POST() method and link the HTML file which saved under
the same directories in the extension .html Step-7: Save the file using file name .php
shop.html <html>
<head><center>
AMAZON SHOPPING
</font></center><br>
<marquee>
NOW!!!HURRY UP!!!
</font></marquee>
</head>
<body>
<center>
<tr>
<th>Product name</th>
<th>Price</th>
</tr>
<tr>
vistaCD</td>
<td>Rs.3000</td>
</tr>
<tr><td>
<input type="checkbox" name="j2eecd" value="J2EE CD"> windows
j2eeCd</td>
<td>Rs.700</td>
</tr>
<tr><td>
<td>Rs.5000</td>
</tr>
<tr>
Studio</td>
<td>Rs.10000</td>
</tr>
</table>
</center>
</form>
</body>
</html>
//shop1.php
<html>
<head>
<center>
SHOPPING CART
</font>
</center>
</head><br>
<?php if(isset($_POST['vistacd']))
{ if($_POST['vistacd']!="")
echo $_POST['vistacd']."<br>";
if(isset($_POST['j2eecd']))
{ if($_POST['j2eecd']!="")
echo $_POST['j2eecd']."<br>";
if(isset($_POST['win7']))
if($_POST['win7']!="") echo
$_POST['win7']."<br>";
if(isset($_POST['vs']))
{ if($_POST['vs']!="")
echo $_POST['vs']."<br>";
?>
</form>
</html>
shop2.php
<?php
echo"<html>
<body>
<center>
<table>
<tr>
<td>
</font>
</td>
</tr>
</table></center>
</body>
</html>";
?>
OUTPUT
EX NO:03
DATE:
Aim:
To develop a PHP program to access the data stored in the MYSQL table.
Procedure:
Step-1: To start and create the database with name.
Step-2: To create a table in the database with table name and insert the data in the table.
Step-3: Save the table.
Step-4: To select the table and view the records.
Step-5: Open the notepad or any IDE and write the PHP program for connecting php to sql
database.
Step-6: To use the new mysqli() funtion and link the database with table.
Step-7: Save the file using file name (connect.php)//connect.php it is a file that we created to
connect php to database. Step-8: save the PHP file as "connect.php".
Step-9: Create another php file to fetch a data from database.
Step-10: connect the connect.php to actual php program to fetch data.
Step-11: save the file as "fetch.php".
Step-12: To connect to any one of the web server WAMP or IIS.
Step-13: Run the program in the localhost/fetch.php // (fetch.php is a php file that we saved).
Step-14: To close the file and exit.
//3.Access table from Database
//db my sql
1.CREATE DATABASE employees_db;
2.USE employees_db;
3.CREATE TABLE employees ( id INT AUTO_INCREMENT PRIMARY KEY, name
VARCHAR(100) NOT NULL, email VARCHAR(100) NOT NULL,
phone VARCHAR(15), hire_date DATE, job_title VARCHAR(100), salary DECIMAL(10, 2)
);
4.INSERT INTO employees (name, email, phone, hire_date, job_title, salary) VALUES
('Alice', 'alice@example.com', '1234567890', '2023-01-15', 'Manager', 75000.00), ('Bob',
'bob@example.com', '0987654321', '2023-02-20', 'Developer', 60000.00);
//fetch a php
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "employees_db";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error); }
$sql = "SELECT id, email, phone, salary, name FROM employees";
$result = $conn->query($sql);
?>
<html>
<head>
<title>Employee</title>
</head>
<body bgcolor="pink">
<center>
<table border=2>
<th>phone no</th>
<th>E.Name</th>
<th>Salary</th>
<th>email</th>
</center>
</body>
</html>
<?php
while($row = $result->fetch_assoc())
{
print
"<tr><td>".$row["phone"]."</td>
<td>".$row["name"]."</td>
<td>".$row["salary"]."</td>
<td>".$row["email"]."</td></tr>";
}
echo"</tr></table></center>";
$result->close();
?>
Aim:
To develop a PHP interface program to create a database and to insert a table into it.
Procedure:
Step-2: To create a table in the database with table name and insert the data in the table.
Step-6: To use the POST() method and link the database with a table.
<?php
$servername = "localhost";
$username = "root";
$password = "yourpasswo";
// 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 myDB";
if ($conn->query($sql) === TRUE) {
echo "Database created successfully<br>";
} else {
echo "Error creating database: " . $conn->error . "<br>";
}
// Create table
$sql = "CREATE TABLE MyGuests (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE
CURRENT_TIMESTAMP
)";
// Close connection
$conn->close();
?>
OUTPUT
EX NO:05
DATE:
Aim:
Procedure:
Step-2: To create a table in the database with table name and insert the data in the table.
Step-5: Open the notepad and write the PHP program with class.
Step-6: To use the POST() method and link the database with table.
if ($this->conn->connect_error) {
die("Connection failed: " . $this->conn->connect_error);
}
// Create database
$sql = "CREATE DATABASE IF NOT EXISTS $this->dbname";
if ($this->conn->query($sql) === TRUE) {
echo "Database created successfully\n";
} else {
echo "Error creating database: " . $this->conn->error;
}
// Method to show all data from a table and print them in an HTML table
public function showTableData($tableName) {
$sql = "SELECT id, firstname, lastname, email, reg_date FROM
$tableName";
$result = $this->conn->query($sql);
if ($result->num_rows > 0) {
echo "<table border='1'>";
echo "<tr><th>ID</th><th>First Name</th><th>Last
Name</th><th>Email</th><th>Registration Date</th></tr>";
while($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row["id"] . "</td><td>" . $row["firstname"] .
"</td><td>" . $row["lastname"] . "</td><td>" . $row["email"] . "</td><td>" .
$row["reg_date"] . "</td></tr>";
}
echo "</table>";
} else {
echo "No records found\n";
}
}
// Destructor to close the database connection
public function __destruct() {
$this->conn->close();
}
}
// Usage
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "myDB";
$db = new Database($servername, $username, $password, $dbname);
$tableName = "MyGuests";
$columns = "id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON
UPDATE CURRENT_TIMESTAMP";
$db->createTable($tableName, $columns);
// Insert data into the table
$data = "('John', 'Doe', 'john@example.com'),
('Mary', 'Moe', 'mary@example.com'),
('Julie', 'Dooley', 'julie@example.com')";
$db->insertData($tableName, $data);
// Show all data from the table
$db->showTableData($tableName);
?>
OUTPUT :
EX NO:06
DATE:
Aim:
Procedure:
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_FILES["fileToUpload"]) &&
$_FILES["fileToUpload"]["error"] == 0)
{
$target_dir = "C:\\Users\\rkris\\OneDrive\\Desktop\\mca\\";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
if (file_exists($target_dir) && move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],
$target_file))
{
echo "File uploaded.";
} else {
echo "Upload error.";
}
}
?>
OUTPUT
EX NO:07
DATE:
Aim:
To develop a PHP program to create a directory and read the condences from the
directories.
Procedure:
Step-6: Exit.
//7.Directory Creation
<?php
$d = 'C:\Users\rkris\OneDrive\Desktop\mca';
if (is_dir($d))
{
echo "Directory already exists.<br>";
}
else
{
mkdir($d, 0777, true);
echo "Directory created.<br>";
}
?>
OUTPUT :
EX NO:08
DATE:
Procedure:
#!/bin/bash
Procedure:
#!/bin/bash
mv "$1" "$2" && echo "Renamed $1 to $2" || echo "Error renaming file"
OUTPUT