-
Notifications
You must be signed in to change notification settings - Fork 225
/
Copy patheditAction.php
33 lines (28 loc) · 1.09 KB
/
editAction.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
<?php
// Include the database connection file
require_once("dbConnection.php");
if (isset($_POST['update'])) {
// Escape special characters in a string for use in an SQL statement
$id = mysqli_real_escape_string($mysqli, $_POST['id']);
$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/>";
}
} else {
// Update the database table
$result = mysqli_query($mysqli, "UPDATE users SET `name` = '$name', `age` = '$age', `email` = '$email' WHERE `id` = $id");
// Display success message
echo "<p><font color='green'>Data updated successfully!</p>";
echo "<a href='index.php'>View Result</a>";
}
}