database.php
1.61 KB
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
<?php
include_once("config.php");
if($_POST['action']==="Delete"){
$id = $_POST['id'];
$query = "DELETE FROM songs WHERE id = $id;";
if(mysqli_query($mysqli,$query)){
echo "Item DELETE Successfully!";
}else{
echo "Item DELETE Faild!";
}
}elseif(!empty($_POST['song_id'])){
$song = $_POST['song_name'];
$singer = $_POST['singer_name'];
$ratings = $_POST['ratings'];
$id = $_POST['song_id'];
if(!empty($_FILES["myimage"]["name"])){
$target_file = "songimages/".basename($_FILES["myimage"]["name"]);
$status = move_uploaded_file($_FILES["myimage"]["tmp_name"],$target_file);
$query = "UPDATE songs
SET song_name = '$song', artist_name = '$singer', song_img = '$target_file', rating_no = '$ratings'WHERE id = $id;";
}else{
$query = "UPDATE songs
SET song_name = '$song', artist_name = '$singer', rating_no = '$ratings'WHERE id = $id;";
}
if(mysqli_query($mysqli,$query)){
echo "Item UPDATE Successfully!";
}else{
echo "Item UPDATE Faild!";
}
}else{
if(!empty($_FILES["myimage"]["name"])){
$song = $_POST['song_name'];
$singer = $_POST['singer_name'];
$ratings = $_POST['ratings'];
$target_file = "songimages/".basename($_FILES["myimage"]["name"]);
$status = move_uploaded_file($_FILES["myimage"]["tmp_name"],$target_file);
$query = "INSERT INTO songs (song_name,artist_name,song_img,rating_no) VALUES ('$song','$singer','$target_file','$ratings')";
if(mysqli_query($mysqli,$query) && $status){
echo "Item Inserted Successfully!";
}else{
echo "Item Inserted Faild!";
}
}else{
echo "Item Inserted Faild!";
}
}
?>