0% found this document useful (0 votes)
28 views4 pages

Crud

This document describes a PHP and MySQL application to perform CRUD operations on a student database. It includes an index.html page with a form to input student data, a connect.php page that inserts the data into a database table, and a display.php page that retrieves and displays the stored data in a table. The application allows adding, retrieving, and viewing student records by name, gender, activity, and mobile number from the activities database table.

Uploaded by

kavya Murugesan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views4 pages

Crud

This document describes a PHP and MySQL application to perform CRUD operations on a student database. It includes an index.html page with a form to input student data, a connect.php page that inserts the data into a database table, and a display.php page that retrieves and displays the stored data in a table. The application allows adding, retrieving, and viewing student records by name, gender, activity, and mobile number from the activities database table.

Uploaded by

kavya Murugesan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Ex.

no: 15 CRUD OPERATION USING PHP AND MYSQL


Date: 02.11.2023

Aim:

To develop a PHP and MySQL application to perform CRUD operation on Student


database.

Program:

Index.html
<html>
<head>
<title>Student Activities</title>
</head>
<body>
<h1>Student Activities</h1>
<form action="connect.php" method="POST">
Name: <input type="text" name="name" required /><br><br>
Gender: Male<input type="radio" name="gender" value="male" required />
Female<input type="radio" name="gender" value="female" required /><br><br>
<label for="activity">Activity:</label>
<select name="activity" id="activity">
<option value="PHP">PHP</option>
<option value="Java" selected>Java</option>
<option value="ReactJs">React Js</option>
<option value="SQL">SQL</option>
</select><br><br>
Mobile: <input type="number" name="phone" required /><br><br>
<input type="submit" />
</form>
<a href="display.php">Show Data</a>
</body>
</html>

Connect.php
<?php
$conn = new mysqli('localhost', 'root', '', 'Student');
if ($conn->connect_error)
die("Error at connecting $conn->connect_error");
if (!empty($_POST)) {
$name = $_POST['name'];
$gender = $_POST['gender'];
$role = $_POST[‘activity’];
$phone = $_POST['phone'];
$query = "insert into activities(name, gender, activity, phone) values ('$name', '$gender',
'$activity, '$phone')";
$stmt = $conn->prepare($query);
$stmt->execute();
echo 'Inserted successfully<br><a href="index.php">Go to index</a>';
}
?>

Display.php

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Display Database Rows</title>
</head>
<body>
<div class="container">
<h1>Student Activities</h1>
<table border="1">
<tr>
<th>ID</th>
<th>Name</th>
<th>Gender</th>
<th>Activity</th>
<th>Mobile</th>
</tr>
<?php
require_once('connect.php');
$result = $conn->query("SELECT * FROM activities");
foreach($result as $rows) {
?>
<tr style="text-align:center">
<td><?php echo $rows['id']; ?></td>
<td><?php echo $rows['name']; ?></td>
<td><?php echo $rows['gender'] ?></td>
<td><?php echo $rows[‘activity’] ?></td>
<td><?php echo $rows['phone'] ?></td>
</tr>
<?php
}
?>
</table>
<br><a href=" index.php">Insert</a>
</div>
</body>
</html>

Output:
Conduct of Experiment (30)
Record(20)
Viva(10)
Total(60)

Result:
Thus, the development of PHP and MySQL application to perform CRUD operations
has been done successfully.

You might also like