-
Notifications
You must be signed in to change notification settings - Fork 0
/
form_database.php
60 lines (53 loc) · 2.32 KB
/
form_database.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Basic information</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
</head>
<body>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$name = $_POST['name'];
$email = $_POST['email'];
$salary = $_POST['salary'];
$servername = "localhost";
$username = "root";
$password = "";
$database_name = "contact_info";
$conn = mysqli_connect($servername, $username, $password, $database_name);
if (!$conn) {
die("connection failed: " . mysqli_connect_error());
}
$insert_query = "INSERT INTO `contacts` (`sno`, `name`, `email`, `salary`, `date`) VALUES ('2', '$name', '$email', '$salary', current_timestamp());";
$success = mysqli_query($conn, $insert_query);
if ($success){
echo '<div class="alert alert-success" role="alert">
saved successfully
</div>';
} else {
echo '<div class="alert alert-danger" role="alert">
Warning: cannot save record now
</div>';
}
}
?>
<div class="container p-5">
<h1>Registration</h1>
<form method="post" action="/learn-php/form_database.php">
<div class="mb-3">
<input name="name" type="text" class="form-control" placeholder="Name">
</div>
<div class="mb-3">
<input name="email" type="email" class="form-control" placeholder="Email">
</div>
<div class="mb-3">
<input name="salary" type="text" class="form-control" placeholder="Salary">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
</body>
</html>