-
Notifications
You must be signed in to change notification settings - Fork 0
/
insertphoto.php
39 lines (37 loc) · 1.22 KB
/
insertphoto.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
include_once 'adminheader.php';
include_once 'connection.php';
$photo = $_FILES["photo"]["tmp_name"];
$productid = $_POST["productid"];
$caption = $_POST["caption"];
$path = '';
$error = '';
if ($photo != "") {
$filename = $_FILES["photo"]["name"];
$ext = pathinfo(strtolower($filename), PATHINFO_EXTENSION);
if (round($_FILES["photo"]["size"] / 1024) > 500) {
$error = "Image size must be less than 100 kb";
header("location:showproduct.php?er=2");
} else {
$path = "photos/$filename";
move_uploaded_file($photo, $path);
}
}
if ($error == "") {
$s = "select * from product_photo where caption='$caption' and productid='$productid'";
$result = mysqli_query($conn, $s);
if (mysqli_num_rows($result) > 0) {
header("Location:showproduct.php?er=3");
} else {
$qury = "INSERT INTO `product_photo`(`id`, `photo`, `caption`, `productid`) VALUES (null ,'$path','$caption','$productid')";
// echo $s;
if (mysqli_query($conn, $qury)) {
header("location:showproduct.php?er=0");
} else {
header("location:showproduct.php?er=1");
}
}
} else {
echo $error;
header("location:showproduct.php?er=$error");
}