-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateItem.php
40 lines (35 loc) · 1.04 KB
/
updateItem.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
<?php
include 'session.php';
if(isset($_POST['btn-upload'])){
foreach($_POST AS $key => $value) { $_POST[$key] = ($value); }
$id = $_POST['id'];
$imgSize = $_FILES['file']['size'];
$imgErrorCode = $_FILES['file']['error'];
$imgData = addslashes(file_get_contents($_FILES['file']['tmp_name']));
$imageProperties = getimageSize($_FILES['file']['tmp_name']);
$sqlNotUpdateImg = "UPDATE output_images
SET
name='{$_POST['name']}',
category='{$_POST['category']}'
WHERE imageId={$id}";
$sqlUpdateImg = "UPDATE output_images
SET
imageType='{$imageProperties['mime']}',
imageData='{$imgData}',
name='{$_POST['name']}',
category='{$_POST['category']}'
WHERE imageId={$id}";
try {
if($imgSize != 0 && $imgErrorCode == 0 && $id > 0){ // imgSize not 0 and file not an error
$result2 = $db->query($sqlUpdateImg);
}
else if($id > 0){
$result3 = $db->query($sqlNotUpdateImg);
}
}
catch(PDOException $ex){
echo "error cannot updating database";
}
header('Location: '.'./editProducts.php?id='.$id);
}
?>