-
Notifications
You must be signed in to change notification settings - Fork 3
/
add_category_.php
36 lines (22 loc) · 944 Bytes
/
add_category_.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
<?php
include 'connection.php';
$name = mysqli_real_escape_string($con, $_POST["name"]);
$uploaddir = 'Image/'.$_SESSION['gamer']['id'].'/'.'Category/';
$uploadfile = $uploaddir . basename($_FILES['pic_cat']['name']);
$st= strrev($_FILES["pic_cat"]['name']);
$ex = strrev(substr($st, 0,strpos($st, ".")));
$uploadfile = $uploaddir . $name . "." . $ex;
$picname = mysqli_real_escape_string($con, $uploadfile);
// Change Name of uploaded file
move_uploaded_file($_FILES['pic_cat']['tmp_name'], $uploadfile);
$d = $_SESSION['id'];
$X=$con->query("SELECT * FROM `category` WHERE name = '$name' and owner = '$d' ;");
if ($X->num_rows == 0) {
$con->query("INSERT INTO `category`(`name`, `pic_loc`,owner) VALUES ('$name','$picname','$d') ;");
}
else{
// update required since extension might change
$con->query("UPDATE `category` SET `pic_loc`='$picname' WHERE `name`='$name' and owner = '$d' ");
}
header('location:index.php');
?>