<?php

require_once 'config.php';
$error=false;
$errors=array();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    
	
	$user_id=$_POST['user_id'];
	//$notification_id=$_POST['notification_id'];
	$query15='SELECT * FROM notifications where id NOT IN (SELECT notification_id FROM notificationby_user WHERE user_id='.$user_id.')';
		$row15 = mysqli_query($con,$query15);
		 if (mysqli_num_rows($row15) >= 1) {	
			 while($r14=mysqli_fetch_array($row15)){
				 
				 $checkEmailExists=mysqli_query($con,"SELECT * FROM notificationby_user WHERE user_id=".$user_id." AND notification_id =".$r14['id']." ");
	
				if(mysqli_num_rows($checkEmailExists)==0){
					
						if($error==false){
						$createCustomer=mysqli_query($con,"INSERT INTO notificationby_user (user_id,notification_id,is_read) VALUES(".$user_id.",".$r14['id'].",1)");
						
						if($createCustomer){
							$errors['success']='Successful Read Notification  ';
							$errors['status']=true;
						}else{
							$error=true;
							$errors['success']='Something went wrong!!!, Please try again.';
							$errors['status']=false;
						}
					}
				
				}
				 
			 }
		 } else{
			$errors['success']='Something went wrong!!!, Please try again.';
			$errors['status']=false;
		 }
	
	echo json_encode($errors);
}

?>