-
Notifications
You must be signed in to change notification settings - Fork 12
/
action.php
executable file
·39 lines (39 loc) · 1.59 KB
/
action.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
<?php
session_start();
include 'dbclass.php';
$db = new DB();
$tblName = 'users';
if(isset($_REQUEST['action_type']) && !empty($_REQUEST['action_type'])){
if($_REQUEST['action_type'] == 'add'){
$userData = array(
'name' => $_POST['name'],
'email' => $_POST['email'],
'phone' => $_POST['phone']
);
$insert = $db->insert($tblName,$userData);
$statusMsg = $insert?'User data has been inserted successfully.':'Some problem occurred, please try again.';
$_SESSION['statusMsg'] = $statusMsg;
header("Location:index.php");
}elseif($_REQUEST['action_type'] == 'edit'){
if(!empty($_POST['id'])){
$userData = array(
'name' => $_POST['name'],
'email' => $_POST['email'],
'phone' => $_POST['phone']
);
$condition = array('id' => $_POST['id']);
$update = $db->update($tblName,$userData,$condition);
$statusMsg = $update?'User data has been updated successfully.':'Some problem occurred, please try again.';
$_SESSION['statusMsg'] = $statusMsg;
header("Location:index.php");
}
}elseif($_REQUEST['action_type'] == 'delete'){
if(!empty($_GET['id'])){
$condition = array('id' => $_GET['id']);
$delete = $db->delete($tblName,$condition);
$statusMsg = $delete?'User data has been deleted successfully.':'Some problem occurred, please try again.';
$_SESSION['statusMsg'] = $statusMsg;
header("Location:index.php");
}
}
}