Skip to content

Commit a656721

Browse files
author
mahfuz
committed
init
0 parents  commit a656721

File tree

5 files changed

+212
-0
lines changed

5 files changed

+212
-0
lines changed

connectDB.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
$host = "localhost";
4+
$username = "root";
5+
$password = "";
6+
$db = "student_db";
7+
8+
$conn = new mysqli($host, $username, $password, $db);

default.css

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
* {
2+
box-sizing: border-box;
3+
}
4+
5+
body {
6+
margin: 0;
7+
padding: 0;
8+
font-family: Arial, Helvetica, sans-serif;
9+
height: 100vh;
10+
}
11+
12+
h1,
13+
h3 {
14+
text-align: center;
15+
}
16+
17+
main {
18+
display: flex;
19+
flex-direction: column;
20+
align-items: center;
21+
justify-content: center;
22+
height: 60%;
23+
}
24+
25+
table {
26+
border-collapse: collapse;
27+
margin-top: 25px;
28+
}
29+
30+
table th,
31+
table td {
32+
border: 1px solid #000;
33+
padding: 5px;
34+
}
35+
36+
form input {
37+
font-size: 15px;
38+
padding: 4px;
39+
}
40+
41+
.btn {
42+
background-color: dodgerblue;
43+
padding: 5px;
44+
cursor: pointer;
45+
text-align: center;
46+
color: #fff;
47+
font-weight: bold;
48+
font-size: 15px;
49+
border: 1px solid #000;
50+
}
51+
52+
a.btn {
53+
display: inline-block;
54+
text-decoration: none;
55+
}
56+
57+
.btn-red {
58+
background-color: red;
59+
}
60+
61+
.btn-green {
62+
background-color: green;
63+
}

delete.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
include './connectDB.php';
3+
4+
// Get id
5+
$id = $_GET['id'];
6+
7+
// $sql = SQL code for executing
8+
$sql = "DELETE FROM students WHERE id=" . $id . "";
9+
10+
// Execute SQL query and if successful, $query=TRUE or $query=FALSE
11+
$query = $conn->query($sql);
12+
13+
if ($query == TRUE) {
14+
// *** Bellow code (commented) should be deleted ***
15+
// Show executable sql code
16+
// echo $sql;
17+
18+
// Go to homepage
19+
header('Location: index.php');
20+
exit();
21+
} else {
22+
echo "Error deleting record: " . $conn->error;
23+
}
24+
25+
// Close database after all work done
26+
$conn->close();

index.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8" />
6+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
8+
<title>Student List App</title>
9+
10+
<link rel="stylesheet" href="default.css" />
11+
</head>
12+
13+
<body>
14+
<h1>Student List App</h1>
15+
<h3>For Educational Tour</h3>
16+
<main>
17+
<form method="POST" action="./insert.php">
18+
<label for="name">Student Name</label>
19+
<input type="text" id="name" name="name" />
20+
21+
<label for="roll">Student ID</label>
22+
<input type="text" id="roll" name="roll" />
23+
24+
<label for="amount">Amount</label>
25+
<input type="text" id="amount" name="amount" value="700" />
26+
27+
<button class="btn" type="submit" class="btn">Add</button>
28+
</form>
29+
<!-- HTML Form: https://www.w3schools.com/tags/tag_form.asp -->
30+
31+
<table>
32+
<thead>
33+
<tr>
34+
<th>#</th>
35+
<th>Student Name</th>
36+
<th>Roll</th>
37+
<th>Amount</th>
38+
<th></th>
39+
</tr>
40+
</thead>
41+
<tbody>
42+
<?php
43+
include './connectDB.php';
44+
45+
$result = $conn->query("SELECT * FROM students");
46+
47+
if ($result->num_rows > 0) {
48+
// *** Bellow code (commented) should be deleted ***
49+
// $text = json_encode($result);
50+
// echo "<script>console.log(" . $text . ");</script>";
51+
52+
while ($row = $result->fetch_assoc()) {
53+
// *** Bellow code (commented) should be deleted ***
54+
$text = json_encode($row);
55+
echo "<script>console.log(" . $text . ");</script>";
56+
57+
echo '<tr>
58+
<td>' . $row['id'] . '</td>
59+
<td>' . $row['name'] . '</td>
60+
<td>' . $row['roll'] . '</td>
61+
<td>' . $row['amount'] . '</td>
62+
<td>
63+
<a class="btn btn-green" href="">Edit</a>
64+
<a class="btn btn-red" href="delete.php?id=' . $row['id'] . '">Delete</a>
65+
</td>
66+
</tr>';
67+
}
68+
}
69+
70+
// *** Bellow code (commented) should be deleted ***
71+
// if ($x = 0) {
72+
// echo "<script>console.log('YES');</script>";
73+
// } else {
74+
// echo "<script>console.log('NO');</script>";
75+
// }
76+
77+
// *** Bellow code (commented) should be deleted ***
78+
// while ($x = 1) {
79+
// echo "<script>console.log('YES');</script>";
80+
// }
81+
?>
82+
</tbody>
83+
</table>
84+
<!-- HTML Table: https://www.w3schools.com/tags/tag_table.asp -->
85+
</main>
86+
</body>
87+
88+
</html>

insert.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
include './connectDB.php';
3+
4+
// Getting values of name, roll amount from the HTML form
5+
$name = $_POST['name'];
6+
$roll = $_POST['roll'];
7+
$amount = $_POST['amount'];
8+
9+
// $sql = SQL code for executing
10+
$sql = "INSERT INTO students (name, roll, amount) VALUES ('" . $name . "', " . $roll . ", " . $amount . ")";
11+
12+
// Execute SQL query and if successful, $query=TRUE or $query=FALSE
13+
$query = $conn->query($sql);
14+
15+
if ($query == TRUE) {
16+
// *** Bellow code (commented) should be deleted ***
17+
// Show executable sql code
18+
// echo $sql;
19+
20+
// Go to homepage
21+
header('Location: index.php');
22+
exit();
23+
} else {
24+
echo "Error inserting record: " . $conn->error;
25+
}
26+
27+
$conn->close();

0 commit comments

Comments
 (0)