-
Notifications
You must be signed in to change notification settings - Fork 0
/
save_instructions.php
81 lines (63 loc) · 1.96 KB
/
save_instructions.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
<?php
ob_start();
session_start();
$table = isset($_POST['table']) ? htmlentities($_POST['table']) : "";
$condition = isset($_POST['condition']) ? $_POST['condition'] : "";
$fields = isset($_POST['fields']) ? $_POST['fields'] : "";
$datetime = date("Y-m-d H:i:s");
$update_info = $fields;
$update_info['updatedate'] = $datetime;
$return = updateRecord($update_info,$table,stripslashes($condition));
echo $return;
ob_end_flush();
function isHexadecimalString ( $str ) {
if ( preg_match("/^[a-f0-9]{1,}$/is", $str) ) {
return 1;
} else {
return 0;
}
}
function updateRecord($arrayValues, $table, $condition, $autoCommit="yes") {
include_once 'connection.php';
mysqli_autocommit($conn, false);
$table_value = "";
if (empty($arrayValues)) {
echo "Incomplete Parameters Passed";
die();
}
if (!is_array($arrayValues)) {
echo "Parameter Passed is not an Array";
return false;
}
foreach ($arrayValues as $ind => $v) {
//$table_value .= $ind . "= '" . $v . "',";
$firstChar = substr($v,0,1);
if($firstChar == '('){
$table_value .= $ind . "= " . $v . ",";
}else{
$table_value .= $ind . "= '" . $v . "',";
}
}
$table_value = substr($table_value, 0, -1);
try{
$sql = "UPDATE $table SET $table_value WHERE $condition";
//Check if inserted to table, if not rollback
mysqli_query($conn, $sql);
if (mysqli_errno($conn)) {
$errno = mysqli_errno($conn);
mysqli_rollback($conn);
return "error";
} else {
if($autoCommit=="yes"){
mysqli_commit($conn);
return true;
}else{
return true;
}
}
} catch (Exception $e) {
mysqli_rollback($conn);
return "error";
}
}
?>