-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathform.php
More file actions
91 lines (83 loc) · 3.2 KB
/
form.php
File metadata and controls
91 lines (83 loc) · 3.2 KB
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
<?php
// There is two type of method in form:
// post -> Are Secure and send the password, use in most of the cases
// <form action="" method="post"></form>
// get -> get data are show in URL
// <form action="" method="get"></form>
$insert = false;
if(isset($_POST['name'])){
// Set connection variables
$server = "localhost";
$username = "root";
$password = "";
// Create a database connection
$con = mysqli_connect($server, $username, $password);
// Check for connection success
if(!$con){
die("connection to this database failed due to" . mysqli_connect_error());
}
// echo "Success connecting to the db";
// Collect post variables
$name = $_POST['name'];
$gender = $_POST['gender'];
$age = $_POST['age'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$desc = $_POST['info'];
$sql = "INSERT INTO `trip`.`trip` (`name`, `age`, `gender`, `email`, `phone`, `other`, `dt`) VALUES ('$name', '$age', '$gender', '$email', '$phone', '$desc', current_timestamp());";
// echo $sql;
// Execute the query
if($con->query($sql) == true){
// echo "Successfully inserted";
// Flag for successful insertion
$insert = true;
}
else{
echo "ERROR: $sql <br> $con->error";
}
// Close the database connection
$con->close();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<section class="Container"
style="display: flex; justify-content: center; flex-direction: column; align-items: center;">
<h1>Enter You Complete Details</h1>
<?php
if($insert == true){
echo "<p class='submitMsg'>Thanks for submitting your form.</p>";
}
?>
<form action="" method="post" style="display: flex; flex-direction: column;">
<input type="text" name="name" id="name" placeholder="Enter Your Name"><br>
<input type="number" name="age" id="age" placeholder="Enter Your Age"><br>
<input type="email" name="email" id="email" placeholder="Enter Your Email"><br>
<input type="tel" name="phone" id="phone" placeholder="Enter Phone Number"><br>
<input type="password" name="password" id="password" placeholder="Enter password"><br>
<fieldset style="border: none;">
Gender:
<label for="male">
<input type="radio" value="male" name="gender" id="male"> Male
</label>
<label for="female">
<input type="radio" value="female" name="gender" id="female"> Female
</label>
<label for="other">
<input type="radio" value="other" name="gender" id="other"> Other
</label>
</fieldset>
<textarea name="info" id="info" cols="30" rows="10"
placeholder="Add the aditional information"></textarea><br>
<input type="submit" value="SUBMIT">
<input type="reset" value="RESET">
</form>
</section>
</body>
</html>