<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport"/>
    <title>Shayari Admin Panel</title>
</head>

<body style="margin:0px;">

   <div style="background:#263238;box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);padding:20px;color:#fff;">
   SHAYARI ADMIN PANEL
   </div>
   
   <?php
	include_once('includes/configaration.php'); ?>
   
   <?php
	if(isset($_POST['btnSubmit'])){
        
                $cat_id = $_POST['cat_id'];
	        $shayari_text = $_POST['shayari_text'];
	
                $error = array();
			
		if(empty($cat_id)){
			$error['cat_id'] = " <span style='padding:20px;color:red;'>please fill out category field!!</span>";
		}
				
		if(empty($shayari_text)){
			$error['shayari_text'] = " <span style='padding:20px;color:red;'>please fill out text field!!</span>";
		}
                
                if(!empty($cat_id) && !empty($shayari_text)){
                         
                         $sql_query = "INSERT INTO shayari (cat, msg)
						VALUES(?, ?)";
						
		         $stmt = $connect->stmt_init();
		         if($stmt->prepare($sql_query)) {
                                  
                                  $stmt->bind_param('ss',
                                                         $cat_id,
                                                         $shayari_text);
		                  $stmt->execute();
		                  $result = $stmt->store_result();
			          $stmt->close();        
                          }
			  
                          if($result) {
                              $error['msg'] = " <span style='padding:20px;color:green;'>Successfully Added</span>";
			  } else {
			      $error['msg'] = " <span style='padding:20px;color:red;'>Failed</span>";
			  }
		}
           }
	?>

        
   <div style="text-align:center;padding:10px;">
   <div style="margin:10px;">
   <?php echo isset($error['msg']) ? $error['msg'] : '';?>
   <?php echo isset($error['cat_id']) ? $error['cat_id'] : '';?>
   <?php echo isset($error['shayari_text']) ? $error['shayari_text'] : '';?>
       </div>
       <form method="post" action="">

<div style="">
<select name="cat_id" id="cat_id" style="width:90%;padding:10px;" required>
<option value="1">Attitude</option>
<option value="2">Birthday</option>
<option value="3">Friendship</option>
<option value="4">Memories</option>
<option value="5">Good Morning</option>
<option value="6">Good Night</option>
<option value="7">Devotional</option>
<option value="8">Romantic</option>
<option value="9">Sad</option>
<option value="10">Best Wish</option>     
</select>
</div>       
                                    
<div style="">
<textarea name="shayari_text" placeholder="Shayari Text Here" style="height:200px;width:90%;margin:10px;" required></textarea>
</div>

<div style="">
<button type="submit" name="btnSubmit" style="width:90%;height:50px;border:0px;background:#263238;box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);padding:20px;color:#fff;">ADD SHAYARI</button>
</div>  
</form>
</div>

</body>

</html>