-
Notifications
You must be signed in to change notification settings - Fork 225
/
addAction.php
46 lines (38 loc) · 1.26 KB
/
addAction.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
<html>
<head>
<title>Add Data</title>
</head>
<body>
<?php
// Include the database connection file
require_once("dbConnection.php");
if (isset($_POST['submit'])) {
// Escape special characters in string for use in SQL statement
$name = mysqli_real_escape_string($mysqli, $_POST['name']);
$age = mysqli_real_escape_string($mysqli, $_POST['age']);
$email = mysqli_real_escape_string($mysqli, $_POST['email']);
// Check for empty fields
if (empty($name) || empty($age) || empty($email)) {
if (empty($name)) {
echo "<font color='red'>Name field is empty.</font><br/>";
}
if (empty($age)) {
echo "<font color='red'>Age field is empty.</font><br/>";
}
if (empty($email)) {
echo "<font color='red'>Email field is empty.</font><br/>";
}
// Show link to the previous page
echo "<br/><a href='javascript:self.history.back();'>Go Back</a>";
} else {
// If all the fields are filled (not empty)
// Insert data into database
$result = mysqli_query($mysqli, "INSERT INTO users (`name`, `age`, `email`) VALUES ('$name', '$age', '$email')");
// Display success message
echo "<p><font color='green'>Data added successfully!</p>";
echo "<a href='index.php'>View Result</a>";
}
}
?>
</body>
</html>