-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_new_user_process.php
More file actions
70 lines (63 loc) · 2.62 KB
/
add_new_user_process.php
File metadata and controls
70 lines (63 loc) · 2.62 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
<?php
session_start();
require_once("db_connect.php");
$email=isset($_POST['email']) ?trim($_POST['email']) : "";
$full_name=isset($_POST['full_name']) ?trim($_POST['full_name']) : "";
$password=isset($_POST['password']) ?($_POST['password']) : "";
$user_category=isset($_POST['user_category']) ?trim($_POST['user_category']) : "";
$occupation=isset($_POST['occupation']) ?trim($_POST['occupation']) : "";
$address=isset($_POST['address']) ?trim($_POST['address']) : "";
$state=isset($_POST['state']) ?trim($_POST['state']) : "";
$status=isset($_POST['status']) ?trim($_POST['status']) : "";
$date=date("Y-m-d H:i:s");
$_SESSION['email']="$email";
$_SESSION['full_name']="$full_name";
$_SESSION['password']="$password";
$_SESSION['user_category']="$user_category";
$_SESSION['occupation']="$occupation";
$_SESSION['address']="$address";
$_SESSION['state']="$state";
$_SESSION['status']="$status";
if($email=="" || $full_name=="" || $password=="" || $user_category=="" || $occupation=="" || $address=="" || $state=="" || $status=="")
{
$_SESSION['message']="Please make sure all fields are selected/entered correctly!";
$_SESSION['messagetype']="error";
header("location: add_new_user.php");
exit();
}
//check if user already exists
$check_user=mysql_query("select * from users where (email='$email')");
if($check_user==FALSE)
{
$_SESSION['message']="An error encountered accessing the table users!";
$_SESSION['messagetype']="error";
header("location: add_new_user.php");
exit();
}
$total_check_user=mysql_num_rows($check_user);
if($total_check_user>0)
{
$_SESSION['message']="There is already a user with the email ($email).please choose another one";
$_SESSION['messagetype']="error";
header("location: add_new_user.php");
exit();
}
?>
<?php
$insert_sql=mysql_query("insert into users set email='$email', full_name='$full_name', password='$password',user_category='$user_category', occupation='$occupation', state='$state', address='$address', status='$status', date_created='$date'");
if($insert_sql==FALSE)
{
$_SESSION['message']="Error encountered adding user!".mysql_error();
$_SESSION['messagetype']="error";
header("location: add_new_user.php");
exit();
}
else
{
unset($_SESSION['email'], $_SESSION['full_name'], $_SESSION['password'], $_SESSION['user_category'], $_SESSION['occupation'], $_SESSION['state'], $_SESSION['address'], $_SESSION['status']);
$_SESSION['message']="User ($full_name) has been successfully added";
$_SESSION['messagetype']="success";
header("location: manage_users.php");
exit();
}
?>