Welcome Guest, Not a member yet? Register   Sign In
Problem while inserting data
#1

[eluser]webdevron[/eluser]
I’m running an online quiz contest. But this error really disturbing. Please help me to solve this as soon as possible.
This is really an interesting problem for me. The value of the field “vote_for” are coming from a radio button. Sometime it is working. But sometime or for some specific ID it is not working and inserting 0 instead of the value of radio button though I’ve checking on radio button that without selecting that nobody can insert data. So, what is the problem, how to solve this?

If the above text is not enough to describe this problem, please see the image that I posted bellow. This is the table of my database. The “vote_for” field is not storing data properly for each time.


Controller:
Code:
public function play(){
      if(!$this->session->userdata('isl')) // if not logged in
            redirect(base_url().'user/signin');
      $id = $this->GameModel->submit_vote(); //Getting Insert ID
      if($id>0){ $data['message'] = "Done"; }
      else { $data['message'] = "Already Exist"; }
      $data['type'] = 'q';
      $this->load->view('message',$data);
}

Model:
Code:
function check_vote($match){
  $this->db->select('id');
  $this->db->from('fb_wc_vote');
  $this->db->where('voter_id', $this->session->userdata('useridnum'));
  $this->db->where('game_id', $match);
  return $this->db->count_all_results();
}

function submit_vote(){
      $user = $this->session->userdata('useridnum');
      $match = $this->input->post('match');
      $team = $this->input->post('team');
      if($this->check_vote($match) > 0){
            return 0;
      }
      else{
            $this->db->set('voter_id', $user);
            $this->db->set('game_id', $match);
            $this->db->set('vote_for', $team);
            $this->db->set('time', date('Y-m-d H:i:s'));
            $this->db->insert('fb_wc_vote');
            return $this->db->insert_id();
      }
}

Please notice the color of else of submit_vote() method.
#2

[eluser]treenef[/eluser]
if($this->check_vote($match) > 0)

Perhaps you meant

if($this->check_vote($match) == 0){
#3

[eluser]hot_sauce[/eluser]
Code:
if($this->check_vote($match) == 0){
    $this->db->set('voter_id', $user);
    $this->db->set('game_id', $match);
    $this->db->set('vote_for', $team);
    $this->db->set('time', date('Y-m-d H:i:s'));
    $this->db->insert('fb_wc_vote');
    return $this->db->insert_id();
}
return 0;




Theme © iAndrew 2016 - Forum software by © MyBB