Welcome Guest, Not a member yet? Register   Sign In
How can i prevent user vote double
#1

(This post was last modified: 10-07-2015, 01:44 AM by freddy. Edit Reason: edit in controller )

Hello guys, thanks for some help in the past.

I have some stuck, about giving voting product who came from user vote, i already success giving vote but realiaze that user cannot giving double vote,

here is js
Code:
$(document).on("click", "[href='#atas']", function() {
   var value = this.id; //this is id product
       $.ajax({
               type: "post",
               url: base_url +"welcome/rating",
               data: "value=" + value,
               success: function(){
                   alert('data has been inserted');
                   },
               error: function(){
                       alert('Sorry you already vote');
                  }
     
           })
});

Controller
Code:
public function rating() {
          //insert table user

        $id=$this->session->userdata('id_user'); //get id user from session
        $id_product=$this->input->post('value');
        $data=array('id_user'=>$this->session->userdata('id_user'),
                    'id_product_post'=>$this->input->post('value'),
                    );
        $this->model_front->rating($data);

        //update in table product post
        $this->db->set('product_akurat', 'product_akurat+1', FALSE);
        $this->db->where('id_product_post', $id_product);
        $this->db->update('li_product_post');


/*
$this->db->where('id_user',$id);
   $query = $this->db->get('li_product_post_rating');
    if ($query->num_rows() > 0){
      //  should giving error cause user already vote
  }
   else{
      //inserted  data
   }

   */
}

and this is my model
Code:
public function rating($data)
{
//untuk insert ke database
$this->db->insert('li_product_post_rating',$data);
}


I'm trying to prevent in controller don't know where should start ! Thanks
Reply


Messages In This Thread
How can i prevent user vote double - by freddy - 10-07-2015, 01:36 AM
RE: How can i prevent user vote double - by PaulD - 10-08-2015, 07:19 AM



Theme © iAndrew 2016 - Forum software by © MyBB