-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathform1.php
150 lines (124 loc) · 3.83 KB
/
form1.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<!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" />
<link rel="stylesheet" href="https://use.typekit.net/oov2wcw.css" />
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.8/css/intlTelInput.css"
/>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.8/js/intlTelInput.min.js">
</script>
<style>
.container {
max-width: 1350px;
width: 100%;
margin: 50px;
height: auto;
display: block;
}
body {
color: #fcf6f5ff;
font-size: 20px;
font-family: Century gothic;
background: #03001e;
background: -webkit-linear-gradient(to right,
#ec38bc,
#7303c0,
#03001e);
background: linear-gradient(to right, #ec38bc, #7303c0, #03001e);
}
a {
color: snow;
}
h2 {
text-align: center;
}
.form_group {
padding: 10px;
display: block;
}
label {
float: left;
padding-right: 50px;
line-height: 10%;
display: block;
width: 208px;
}
</style>
<title>HTML Form</title>
</head>
<body>
<?php
if (isset($_POST['fname'])) {
$server = "localhost";
$username = "root";
$password = "";
$dbname = "db1";
$con = mysqli_connect($server, $username, $password, $dbname);
if (!$con) {
die("Connection failed !" . mysqli_connect_error());
}
// get the post records
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$dob = $_POST['dob'];
$pno = $_POST['pno'];
$eml = $_POST['eml'];
// database insert SQL code
$sql = "INSERT INTO `table1` (`f_name`, `l_name`, `dob`, `phone_no`, `eml_id`) VALUES ('$fname', '$lname', '$dob', '$pno', '$eml')";
// insert in database
$rs = mysqli_query($con, $sql);
if ($rs) {
echo "<center>Data Saved Successfully! </center>";
echo "<h2><a href='http://localhost/My_php_programs/form1.php' >Fill the form again</a></h2>";
echo "<h2><a href='http://localhost/My_php_programs/form2.php' target='_blank' >View Saved Data in DataBase</a></h2>";
} else {
echo "Error!";
}
} else {
?>
<h2>Enter your information</h2>
<form name="form1" action="form1.php" method="post"
enctype="multipart/form-data">
<div class="container">
<div class="form_group">
<label>First Name:</label>
<input type="text" name="fname" value="" required />
</div>
<div class="form_group">
<label>Last Name:</label>
<input type="text" name="lname" value="" required />
</div>
<div class="form_group">
<label>Date of Birth : </label>
<input type="date" name="dob" value="" required />
</div>
<div class="form_group">
<label>Phone Number : </label>
<input type="tel" id="phone" name="pno" value="" required />
</div>
<div class="form_group">
<label>E-mail ID : </label>
<input type="email" name="eml" value="" required />
</div>
<br />
<div class="form_group" class="btn">
<input type="submit" value="submit" />
</div>
</div>
</form>
<?php
}
?>
</body>
<script>
const phoneInputField = document.querySelector("#phone");
const phoneInput = window.intlTelInput(phoneInputField, {
preferredCountries: ["in"],
utilsScript: "https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.8/js/utils.js",
});
</script>
</html>