<?php
include 'side_nav.php';
include 'main.php';
// initializing variables
$title = "";
$bhajan = "";
$type = "";
// connect to the database
include_once 'db_connection.php';

// UPLOAD IMAGE
if(isset($_POST['submit_button'])) {
  // receive all input values from the form
  $title = mysqli_real_escape_string($connect, $_POST['title']);
  $bhajan = mysqli_real_escape_string($connect, $_POST['bhajan']);
  $type = mysqli_real_escape_string($connect, $_POST['type']);
  
  // first check the database to make sure 
  // a user does not already exist with the same username and/or email
  $bhajan_check_query = "SELECT * FROM kapaleshwar WHERE title='".$title."'";
  $result =  mysqli_num_rows(mysqli_query($connect, $bhajan_check_query));
  if ($result >= 0) {
  	$query = "INSERT INTO kapaleshwar(title,bhajan,type) VALUES ('$title','$bhajan','$type')";
    if (mysqli_query($connect,$query)) 
    {
    $_SESSION['title'] = $title;
    echo '<script>alert("$title Bhajan Added successfully");</script>'; 
  	}
  }
  else
  {
    echo '<script>alert("'.$title.' Bhajan Already Present");</script>';
  }
}
?>
<!DOCTYPE html>
<html>
<head>
	<title>Add Bhajan</title>
</head>
<link rel="stylesheet" type="text/css" href="css/btn.css">
<link rel="stylesheet" type="text/css" href="style.css">
<body>
<div class="header">
    <h2>Add Bhajan</h2>
  </div>
	<form method="post" action="add_bhajan.php" enctype="multipart/form-data">
	<div class="input-group">
		<label>Bhajan Name</label>
		<input type="text" name="title" required><br>
	</div>
	<div class="input-group">
		<label>Bhajan</label>
		<input type="text" name="bhajan" required><br>
	</div>
	<div class="input-group">
	<select name="type" name="type" required>
  		<option value="kapaleshwar">Kapaleshwar</option>
  		<option value="devi">Devi</option>
  		<option value="datta">Datta</option>
  		<option value="shankarbaba">Shankarbaba</option>
  		<option value="stotra">Stotra</option>
	</select>
</div>
	<center>
	<div class="input-group">
		<button class="btn" type="submit" name="submit_button">Submit</button>
	</div>
	</center>
	</form>
</body>
</html>