-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadd.php
More file actions
54 lines (46 loc) · 1.7 KB
/
add.php
File metadata and controls
54 lines (46 loc) · 1.7 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
<html>
<head>
<title>Add User</title>
</head>
<body>
<?php
//including the database connection file
include_once("config.php");
if(isset($_POST['Submit'])) {
//$id = mysqli_real_escape_string($mysqli, $_POST['id']);
// print_r($_POST)die;
$name = mysqli_real_escape_string($con, $_POST['username']);
$email = mysqli_real_escape_string($con, $_POST['email']);
//$role_query = mysqli_query($mysqli, "Select role_id from role where role_name='$_POST['role_id']'");
$role_id = mysqli_real_escape_string($con, $_POST['role_name']);
$password = mysqli_real_escape_string($con, $_POST['password']);
// checking empty fields
if(empty($name) || empty($role_id) || empty($email) || empty($password)) {
if(empty($name)) {
echo "<font color='red'>Name field is empty.</font><br/>";
}
if(empty($role_id)) {
echo "<font color='red'>Role field is empty.</font><br/>";
}
if(empty($email)) {
echo "<font color='red'>Email field is empty.</font><br/>";
}
if(empty($password)) {
echo "<font color='red'>Password field is empty.</font><br/>";
}
//link to the previous page
echo "<br/><a href='index.php'>Go Back</a>";
} else {
// if all the fields are filled (not empty)
//echo "INSERT INTO users(username,password,email,role_id) VALUES('$name','$password','$email','$role_id',)";die;
//insert data to database
$result = mysqli_query($con, "INSERT INTO users(username,password,email,role_id) VALUES('$name','$password','$email','$role_id')");
//echo $result;
//display success message
echo "<font color='green'>Data added successfully.";
echo "<br/><a href='index.php'>View Result</a>";
}
}
?>
</body>
</html>