Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8338919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:44:24+00:00 2026-06-09T04:44:24+00:00

I want to check (before submit to db) whenever there is a game in

  • 0

I want to check (before submit to db) whenever there is a game in database which has title and platform the same as the one submitted.

I have this controller:

    public function addGame($id = null) { // ID is for children games
    $this->load->library(array('images','form_validation'));
    $this->load->helper('form');
    $this->load->model('contrib_model');

    $this->form_validation->set_rules('gameTitle', 'Tytuł gry', 'required|callback_checkGamePlatform');

    if($this->form_validation->run() == FALSE) {
        $data['title'] = 'Dodaj grę';
        $data['genres'] = $this->contrib_model->getGenres();
        $data['platforms'] = $this->contrib_model->getPlatforms();
        $data['developers'] = $this->contrib_model->getDevelopers();

        $this->template->load('template','theme/contribute/addGame',$data);
    } else {
        $data['submit'] = $this->contrib_model->insertGame();; //submits data
        $this->load->view('theme/contribute/emptyPage', $data); //loads view
    }
}

public function checkGamePlatform() {
    $platform = $this->input->post('gamePlatform');
    $game = $this->input->post('gameTitle');

    $q = $this->contrib_model->checkGame($game,$platform);
    echo $q;
    if($q === '0') {
        $this->form_validation->set_message('checkGamePlatform','gra istnieje');
    }
}

And this model:

    function checkGame($name,$platform) {
    $q = $this->db->get_where('games',array(
        'name' => $name,
        'plat' => $platform
    ));

    return $q -> num_rows();

}

The problem is, it doesn’t work at all. What I am doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T04:44:26+00:00Added an answer on June 9, 2026 at 4:44 am

    If there is a game of the same type, you will want to return an error message.
    Furthermore, the callback must return boolean values.

    In checkGamePlatform:

    if ($q > 0) {
         $this->form_validation->set_message('checkGamePlatform','gra istnieje');
         return FALSE;
    }
    return TRUE;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to check my database for records that I already have recorded before
Before Entering data into a database, I just want to check that the database
I want to check whether the endpoint is defined in the configuration before I'll
I have a user-defined table type. I want to check it's existence before editing
I want to check which port is used, when the port is not explicitly
I have a form which I want to submit only if a condition is
I have an Activity, which contains a bunch of check boxes and a submit
I have a form, and before it submits I want to check some of
I'm writing a little web-app and want to check the users connectivity before I
I want to check on the client side that a file has been selected

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.