Phpprac
Phpprac
Phpprac
Class: BCA 5A
IU NO. :IU2282820052
1. Create two tables: Student_Details (EnrollmentNo, Name, Emailid, PhoneNo) and
Student_Marks (EnrollmentNo, Marks1, Marks2, Marks3, Marks4,Marks5, Total & Percentage).
A. Write a PHP script to calculate the total and percentage of each student before inserting the
record. Insert Minimum 8 records in each table.
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "Studentinfo";
if (!$conn) {
Name VARCHAR(100),
Emailid VARCHAR(100),
if (mysqli_query($conn, $sql1)) {
} else {
EnrollmentNo INT,
Marks1 INT,
Marks2 INT,
Marks3 INT,
Marks4 INT,
Marks5 INT,
Total INT,
Percentage FLOAT,
PRIMARY KEY (EnrollmentNo),
)";
if (mysqli_query($conn, $sql2))
} else {
$students = [
['EnrollmentNo' => 1, 'Name' => 'Jiya Acharya', 'Emailid' => 'achjiya12@gmail.com', 'PhoneNo' =>
'0987465123'],
['EnrollmentNo' => 2, 'Name' => 'Kishan Patel', 'Emailid' => 'notkey76@gmail.com', 'PhoneNo' =>
'9426100336'],
['EnrollmentNo' => 3, 'Name' => 'Krishav Acharya', 'Emailid' => 'achkri122@gmail.com', 'PhoneNo'
=> '9270642319'],
['EnrollmentNo' => 4, 'Name' => 'Faizan Shaikh', 'Emailid' => 'faixz34@gmail.com', 'PhoneNo' =>
'9988776655'],
['EnrollmentNo' => 5, 'Name' => 'Devarshi Panchal', 'Emailid' => 'deva234@gmail.com', 'PhoneNo'
=> '9316428544'],
['EnrollmentNo' => 6, 'Name' => 'Jimmy Mehta', 'Emailid' => 'jimjam76@gmail.com', 'PhoneNo' =>
'9735421678'],
['EnrollmentNo' => 7, 'Name' => 'Vishu Parikh', 'Emailid' => 'vsih298@gmail.com', 'PhoneNo' =>
'3658345830'],
['EnrollmentNo' => 8, 'Name' => 'Tirth Soni', 'Emailid' => 'titi46@gmail.com', 'PhoneNo' =>
'8665478688']
];
if (mysqli_query($conn, $sql_insert_student))
$marks = [
['EnrollmentNo' => 1, 'Marks1' => 50, 'Marks2' => 80, 'Marks3' => 75, 'Marks4' => 73, 'Marks5' =>
45],
['EnrollmentNo' => 2, 'Marks1' => 60, 'Marks2' => 75, 'Marks3' => 50, 'Marks4' => 67, 'Marks5' =>
75],
['EnrollmentNo' => 3, 'Marks1' => 70, 'Marks2' => 55, 'Marks3' => 90, 'Marks4' => 87, 'Marks5' =>
65],
['EnrollmentNo' => 4, 'Marks1' => 75, 'Marks2' => 48, 'Marks3' => 42, 'Marks4' => 85, 'Marks5' =>
77],
['EnrollmentNo' => 5, 'Marks1' => 70, 'Marks2' => 72, 'Marks3' => 56, 'Marks4' => 94, 'Marks5' =>
81],
['EnrollmentNo' => 6, 'Marks1' => 67, 'Marks2' => 94, 'Marks3' => 80, 'Marks4' => 87, 'Marks5' =>
66],
['EnrollmentNo' => 7, 'Marks1' => 55, 'Marks2' => 98, 'Marks3' => 55, 'Marks4' => 88, 'Marks5' =>
57],
['EnrollmentNo' => 8, 'Marks1' => 80, 'Marks2' => 68, 'Marks3' => 82, 'Marks4' => 54, 'Marks5' =>
89]
];
$percentage = $total / 5;
if (mysqli_query($conn, $sql_insert_marks)) {
} else {
}
}
mysqli_close($conn);
?>
B. Write a php script to display all the records of the Student_Marks table in a tabular format. Use
appropriate HTML tags for the same.
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "Studentinfo";
if (!$conn) {
<tr>
<th>EnrollmentNo</th>
<th>Marks1</th>
<th>Marks2</th>
<th>Marks3</th>
<th>Marks4</th>
<th>Marks5</th>
<th>Total</th>
<th>Percentage</th>
</tr>";
echo "<tr>";
echo "</tr>";
echo "</table>";
mysqli_close($conn);
?>
C. Create a HTML form to accept EnrollmentNo & new mobile number from the user. Write a php
script to update the student record with the new mobile number for the student with the
EnrollmentNo provided by the user.
D. Delete any two records of the students from the Student_Marks table.
E. Create a HTML form to accept a value from the user. Delete records from Student_Marks, of
those students where total marks is less than the value provided by the user.
Use the tables created in B and create php scripts to implement CRUD (Insert, Select,
Update, Delete) operations on the tables using HTML forms for accepting inputs from
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
</head>
<body>
</form>
</body>
</html>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "Studentinfo";
if (!$conn) {
$enrollmentno = $_POST['enrollmentno'];
$newmobileno = $_POST['newmobileno'];
if (mysqli_query($conn, $sql)) {
} else {
mysqli_close($conn);
?>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "Studentinfo";
if (!$conn) {
if (mysqli_query($conn, $sql)) {
} else {
mysqli_close($conn);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
</head>
<body>
</form>
</body>
</html>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "Studentinfo";
if (!$conn) {
$min_marks = $_POST['min_marks'];
if (mysqli_query($conn, $sql)) {
} else {
mysqli_close($conn);
?>
2. Use the tables created in B and create php scripts to implement CRUD (Insert, Select, Update,
Delete) operations on the tables using HTML forms for accepting inputs from the user. Provide the
CRUD operation using an index.html page.
<!DOCTYPE html>
<html lang="en">
<head>
<title>CRUD Operations</title>
</head>
<body>
</form>
</form>
</form>
</form>
</body>
</html>
3. Create a class Book, to store details like ISBN number, Book name, price, pages and publication.
Create a Constructor to initialize the ISBN number, Book name, price, pages and publication with
appropriate values. Create one member functions to display the Book details in tabular format
with a heading using HTML tags.
<?php
class Book {
private $isbn;
private $name;
private $price;
private $pages;
private $publication;
$this->isbn = $isbn;
$this->name = $name;
$this->price = $price;
$this->pages = $pages;
$this->publication = $publication;
echo "<tr>
<th>ISBN</th>
<th>Book Name</th>
<th>Price</th>
<th>Pages</th>
<th>Publication</th>
</tr>";
echo "<tr>
<td>{$this->isbn}</td>
<td>{$this->name}</td>
<td>{$this->price}</td>
<td>{$this->pages}</td>
<td>{$this->publication}</td>
</tr>";
echo "</table>";
$book2 = new Book("031-32-139", "The Pragmatic Programmer: Your Journey to Mastery", 39.99,
420, "Andrew Publications");
$book1->displayBookDetails();
$book2->displayBookDetails();
?>
4. Create a HTML page to accept username and password from the user. Also provide a submit
button labelled - “Login”. Use Session to store the username and set a unique UserId value. On the
click of submit button, call a php script which displays a welcome message as:
Hello <username>.
Also provide the following options to the user, below the welcome message:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Login</title>
</head>
<body>
<h2>Login</h2>
<label for="username">Username:</label>
<label for="password">Password:</label>
<input
type="password"
id="password"
name="password"
required
<button type="submit">Login</button>
</form>
</body>
</html>
<?php
session_start();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST['username'];
$password = $_POST['password'];
$_SESSION['username'] = $username;
</form>";
if (isset($_POST['display'])) {
} else {
} elseif (isset($_POST['destroy'])) {
session_unset();
session_destroy();
echo "<p>Session has been destroyed.</p>";
?>
5. Create a HTML page to accept username and password from the user. Use cookies to store the
username and set the time such that it will destroy after 2 minutes.
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<h2>Login</h2>
<label for="username">Username:</label>
<label for="password">Password:</label>
<input
type="password"
id="password"
name="password"
required
<button type="submit">Login</button>
</form>
</body>
</html>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST['username'];
$password = $_POST['password'];
header("Location: welcome.php");
exit();
?>
<?php
if (isset($_COOKIE['username'])) {
$username = $_COOKIE['username'];
} else {
echo "<p>Your session has expired or you are not logged in.</p>";
?>