-
Notifications
You must be signed in to change notification settings - Fork 0
/
query.php
110 lines (96 loc) · 2.89 KB
/
query.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
function is_admin_login()
{
if(!isset($_SESSION['admin']))
{
header('location:login.php');
}
}
function is_soc_login()
{
if(!isset($_SESSION['soc_id']))
{
header('location:login.php');
}
}
function dbRowInsert($table_name, $form_data)
{
// retrieve the keys of the array (column titles)
$fields = array_keys($form_data);
// build the query
$sql = "INSERT INTO ".$table_name."
(`".implode('`,`', $fields)."`)
VALUES('".implode("','", $form_data)."')";
//print_r($sql); exit();
// run and return the query result resource
$status = mysqli_query($GLOBALS['con'],$sql);
if($status)
{ //echo "yes"; exit();
$_SESSION['suc_msg'] = "data inserted sucessfully.";
}
else
{ //echo "no"; exit();
$_SESSION['error_msg'] = "data not inserted sucessfully.";
}
return;
}
function listing($table_name)
{ $arr = "";
$sql = "SELECT *
FROM ".$table_name."
WHERE society_id = '".$_SESSION['soc_id']."'
";
if($rs = mysqli_query($GLOBALS['con'],$sql)) {
$arr[] = mysqli_fetch_array($rs);
}
return $arr;
}
function fetchsinglerow($table_name,$userid,$columnname)
{ $arr = array();
$sql = "SELECT *
FROM ".$table_name."
WHERE society_id = '".$_SESSION['soc_id']."' AND
".$columnname." = '".$userid."'
";
if($rs = mysqli_query($GLOBALS['con'],$sql)) {
$arr = mysqli_fetch_array($rs);
}
//print_r($arr); exit;
return $arr;
}
function upload_file($image_name,$path) {
$filename=str_replace(" ","_",$_FILES[$image_name]['name']);
$tmpname=$_FILES[$image_name]['tmp_name'];
$exp=explode('.', $filename);
$ext=end($exp);
$newname= $exp[0].'_'.time().".".$ext;
move_uploaded_file($tmpname,$image_path);
return $newname;
}
function update($table,$column,$id,$fields) {
$set = '';
$x = 1;
foreach($fields as $name => $value) {
$set .= "{$name} = \"{$value}\"";
if($x < count($fields)) {
$set .= ',';
}
$x++;
}
$sql = "UPDATE {$table} SET {$set} WHERE {$column} = {$id}";
//echo $sql; exit();
$status = mysqli_query($GLOBALS['con'],$sql);
if($status)
{ //echo "yes"; exit();
$_SESSION['suc_updatemsg'] = "data update sucessfully.";
}
else
{ //echo "no"; exit();
$_SESSION['error_msg'] = "data not inserted sucessfully.";
}
// if(!$this->query($sql, $fields)->error()) {
// return true;
// }
// return false;
}
?>