-
Notifications
You must be signed in to change notification settings - Fork 0
/
file-handling.php
106 lines (78 loc) · 2.3 KB
/
file-handling.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
<!DOCTYPE html>
<html>
<head>
<title>Registration Form Self</title>
</head>
<body>
<h1>Registration Form Self</h1>
<?php
$firstNameErr = $lastNameErr = $emailErr = $genderErr = "";
$firstName = "";
$lastName = "";
$gender = "";
$email = "";
if($_SERVER["REQUEST_METHOD"] == "POST") {
if(empty($_POST['fname'])) {
$firstNameErr = "Please fill up the first name properly";
}
else {
$firstName = $_POST['fname'];
}
if(empty($_POST['lname'])) {
$lastNameErr = "Please fill up the last name properly";
}
else {
$lastName = $_POST['lname'];
}
if(empty($_POST['gender'])) {
$genderErr = "Please select the gender properly";
}
else {
$gender = $_POST['gender'];
}
if(empty($_POST['email'])) {
$emailErr = "Please fill up the email properly";
}
else {
$email = $_POST['email'];
}
if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$email)) {
$emailErr = "Invalid URL";
}
else {
$email = $_POST['email'];
}
$filePath = "RGDetails.txt";
$f1 = fopen($filePath, "a");
fwrite($f1, $firstName."\n");
fwrite($f1, $lastName."\n");
fwrite($f1, $gender."\n");
fwrite($f1, $email."\n");
fclose($f1);
}
?>
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
<!-- Input Text Field -->
<label for="fname">First Name</label>
<input type="text" name="fname" id="fname" value="<?php echo $firstName; ?>">
<p style="color:red"><?php echo $firstNameErr; ?></p>
<br>
<label for="lname">Last Name</label>
<input type="text" name="lname" id="lname" value="<?php echo $lastName ?>">
<p><?php echo $lastNameErr; ?></p>
<br>
<label for="gender">Gender:</label>
<input type="radio" id="male" name="gender" value="male">
<label for="male">Male </label>
<input type="radio" id="female" name="gender" value="female">
<label for="female">Female </label>
<br><br>
<label for="email">Email:</label>
<input type="txt" name="email" id="email" value="<?php echo $email ?>">
<p><?php echo $emailErr; ?></p>
<br>
<!-- Input submit -->
<input type="submit" value="Submit">
</form>
</body>
</html>