database.php 1.61 KB
<?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!";
		}
	}
	
	



	
	
?>