File "like_dislike_product.php"

Full Path: /home/u165092617/domains/tadzz.com/public_html/forms/like_dislike_product.php
File size: 2.72 KB
MIME-type: text/x-php
Charset: utf-8

<?php session_start();
   include("../config/config.php");
   $myformId=SESS_MASTER;
   $myIp= ipCheck() ;
   $dateceated=date("Y-m-d G:i:s");
   $createdby='0';
   
   $alertType='1';// ADMIN=1 USER =0
   $id		=	secureSuperGlobalPOST($_REQUEST['id']);
   $type	=	secureSuperGlobalPOST($_REQUEST['type']);
     if(!empty($_SESSION[ADD_TAG.'_UserId_vendor'])){
         $u_type='vendor';
       $user_id=$_SESSION[ADD_TAG.'_UserId_vendor'];  
     }
     elseif(!empty($_SESSION[ADD_TAG.'_UserId_user'])){
           $user_id=$_SESSION[ADD_TAG.'_UserId_user'];
            $u_type='user';
         
     }
      $sql = "SELECT * FROM product_master WHERE rowId ='$id' ";
   	 
      	$myquery=$conn->query($sql); 
   	$mydara= $myquery->fetchAll()  ;
   	
   	$rows_found = $myquery->rowCount();
   	 
   			foreach( $mydara as $row ) {
   				$total_likes	= $row['total_likes'];
   				$total_dislikes		= $row['total_dislikes'];
   				
   		}
   
   
   if($user_id!='' && $type=='1' ){
    
   				
   			$total_likes=$total_likes+1;
   		
   
     try{
   		$olgaquery="INSERT INTO like_master SET coupan_id='$id',user_type='$u_type',like_status='$type',user_id='$user_id'"; 
   		$stmt = $conn->prepare($olgaquery);
   		if($stmt->execute()){
   			$last_insert_id = $conn->lastInsertId();
   
   			$olgaquerys="UPDATE product_master SET total_likes='$total_likes' WHERE rowId='$id' "; 
   		$stmts = $conn->prepare($olgaquerys);
   		if($stmts->execute()){
   
   		echo '<a onclick="return cwRating('.$id.', 0,'.$id.');" title="I Like This"><i class="fa fa-thumbs-up text-success" aria-hidden="true"></i>
   &nbsp;'.$total_likes.'</a>';
   
   		
   		}
    
    
      } }
            
           // show error
           catch(PDOException $exception){
               die('ERROR: ' . $exception->getMessage());
           }
   }elseif($user_id!='' && $type=='0'){
       	$total_likes=$total_likes-1;
       	try{
   		$olgaquery="DELETE FROM like_master WHERE coupan_id='$id' AND user_type='$u_type' AND user_id='$user_id'"; 
   		$stmt = $conn->prepare($olgaquery);
   		if($stmt->execute()){
   			$last_insert_id = $conn->lastInsertId();
   
   			$olgaquerys="UPDATE product_master SET total_likes='$total_likes' WHERE rowId ='$id' "; 
   		$stmts = $conn->prepare($olgaquerys);
   		if($stmts->execute()){
   
   	 echo '<a onclick="return cwRating('.$id.', 1,'.$id.');" title="I Like This"><i class="fas fa-thumbs-up"  ></i>&nbsp;'.$total_likes.'</a>';
   
   	
   
   		
   		}
    
    
      } }
            
           // show error
           catch(PDOException $exception){
               die('ERROR: ' . $exception->getMessage());
           }
       	
      
   }
   ?>