Crud
Crud
Aim:
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.