Created
June 27, 2022 06:15
-
-
Save msisaifu/feff4b0db0ed143b0931368c5bb66482 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$servername = "localhost"; | |
$username = "root"; | |
$password = ""; | |
$dbname = "students"; | |
$table_name = 'student_info'; | |
$inserted = false; | |
$something_wrong = false; | |
// Create connection | |
$conn = mysqli_connect($servername, $username, $password, $dbname); | |
// Check connection | |
if (!$conn) { | |
die("Connection failed: " . mysqli_connect_error()); | |
} | |
if ($_POST && isset($_POST['submit'])) { | |
$name = $_POST['name'] ? $_POST['name'] : ''; | |
$roll = $_POST['roll'] ? $_POST['roll'] : ''; | |
$department = $_POST['department'] ? $_POST['department'] : ''; | |
$sql = "INSERT INTO {$table_name} (name, roll, department) | |
VALUES ('{$name}', '{$roll}', '{$department}')"; | |
if (mysqli_query($conn, $sql)) { | |
$inserted = true; | |
} else { | |
$something_wrong = true; | |
echo "Error: " . $sql . "<br>" . mysqli_error($conn); | |
} | |
} | |
?> | |
<!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>Document</title> | |
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.4/css/bulma.min.css"> | |
</head> | |
<body> | |
<div class="container"> | |
<div class="notification is-light"> | |
<h2 class="is-flex is-justify-content-center has-text-weight-bold is-size-4">Database Management System</h2> | |
</div> | |
<div class="panel is-danger"> | |
<p class="panel-tabs"> | |
<a href="index.php">List</a> | |
<a href="add.php" class="is-active">Add</a> | |
</p> | |
<?php | |
if ($inserted) { ?>. | |
<div class="columns mt-4"> | |
<div class="column is-6 is-offset-3"> | |
<article class="message is-success"> | |
<div class="message-body"> | |
Data insertion successful. | |
</div> | |
</article> | |
</div> | |
</div> | |
<?php } ?> | |
<?php | |
if ($something_wrong) { ?>. | |
<div class="columns mt-4"> | |
<div class="column is-6 is-offset-3"> | |
<article class="message is-danger"> | |
<div class="message-body"> | |
Something wrong in insertion. | |
</div> | |
</article> | |
</div> | |
</div> | |
<?php } ?> | |
<div class="columns mt-4"> | |
<div class="column is-6 is-offset-3"> | |
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post"> | |
<div class="field"> | |
<label class="label">Name</label> | |
<div class="control"> | |
<input required class="input" name="name" type="text" placeholder="Student Name"> | |
</div> | |
</div> | |
<div class="field"> | |
<label class="label">Roll</label> | |
<div class="control"> | |
<input required class="input" name="roll" type="text" placeholder="Roll"> | |
</div> | |
</div> | |
<div class="field"> | |
<label class="label">Department</label> | |
<div class="control"> | |
<input required class="input" name="department" type="text" placeholder="Department"> | |
</div> | |
</div> | |
<div class="field is-grouped"> | |
<div class="control"> | |
<input type="submit" class="button is-link" name="submit" value="Submit"> | |
</div> | |
</div> | |
</form> | |
</div> | |
</div> | |
</div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment