I am creating a custom joomla module based on form submission but i am having some problems in inserting the values I have a html form which has certain fieldsets which pass values to mod_score.php which checks for empty validation and proceeds for helper.php where i have the function for inserting the form values.

Testing it on my localhost (XAMPP )
Version 3.4
Template Protostar

  // This is the class

class modScoreCardHelper
    function saveCard($params)
        $input= new JInput;
        $match_id           =   $input->get('match_id',null);
        $match_time         =   $input->get('match_time',null);
        $match_venue        =   $input->get('match_venue',null);
        $match_team_one     =   $input->get('match_team_one',null);
        $match_team_two     =   $input->get('match_team_two',null);
        $match_result       =   $input->get('match_result',null);
        $match_umpire_one   =   $input->get('match_umpire_one',null);
        $match_umpire_two   =   $input->get('match_umpire_two',null);
        $match_mom          =   $input->get('match_mom',null);
        $match_toss         =   $input->get('match_toss',null);
        $match_fow          =   $input->get('match_fow',null);
        $match_comments     =   $input->get('match_comments',null);
        $match_debutants    =   $input->get('match_debutants',null);

        // Get a db connection.
        $db = JFactory::getDbo();
        echo 'starting to insert in db';
        // Create a new query object.
        $query = $db->getQuery(true);

        // Insert columns.
        $columns = array('match_id', 'match_time', 'match_venue', 'match_result','match_team_one',

        $values = array($match_id, $match_time, $match_venue,$match_result,$match_team_one,

        // Prepare the insert query.
         ->values(implode(',', $values));

        // Set the query using our newly populated query object and execute it.


I simply copied the query in phpmyadmin and executed the code it gave me error 1064 as it is showing on the site.I searched a lot on google and added double quotes to the column values field like "MI "," RCB " in phpmyadmin and the query executed sucessfully .there but i do not know how to add double quotes.Also in the query it is deleting the spaces in the values
For example : actual value = MI won becomes MIwon.

how to remove those spaces and double quotes in my query and remove this error Thanks in advance

enter image description here

  • Are you sure all the columns you have defined such as match_id exist? Have you also ensured that all the values are being pulled correctly? Try var_dump($match_id); and see what the outcome is
    – Lodder
    Commented May 15, 2015 at 11:33
  • Yes I have checked all the columns.Where should i add this var_dump. In my helper.php or mod_score.php ! Commented May 15, 2015 at 11:41
  • Add it before your database query
    – Lodder
    Commented May 15, 2015 at 11:54

2 Answers 2


Replace your $input with following:

$input = JFactory::getApplication()->input

Use $db->quote($name_of_your_value_var);

So your $values will be as follows:

$values = array($match_id, $db->quote($match_time), $db->quote($match_venue),$db->quote($match_result),$db->quote($match_team_one),

You can omit $db->quote if you are passing integer to the database. for e.g. I've not added $db->quote for $match_id. (assuming you are passing integer in that variable)

Also, I would suggest you to use JTable method for CRUD operations on database. It will surely make your life easier.

  • It worked but it is still storing values in the database like MIwon instead of MI won. Thank your for help ! Commented May 15, 2015 at 11:52
  • What is the method of your form? GET or POST? You should first consider printing $values array with print_r($values) and provide the output here. Commented May 15, 2015 at 12:00
  • post ! okay i am going to try that ! Commented May 15, 2015 at 12:03

Just a little to expand on @Sahil Purav's answer. The reason why your values might not be being stored as they should is because you need to define a filter in your inputs.

Try adding RAW to all of them, like so:

$match_id           =   $input->get('match_id', null, 'RAW');
$match_time         =   $input->get('match_time', null, 'RAW');
$match_venue        =   $input->get('match_venue', null, 'RAW');
$match_team_one     =   $input->get('match_team_one', null, 'RAW');
$match_team_two     =   $input->get('match_team_two' null, 'RAW');
$match_result       =   $input->get('match_result', null, 'RAW');
$match_umpire_one   =   $input->get('match_umpire_one', null, 'RAW');
$match_umpire_two   =   $input->get('match_umpire_two', null, 'RAW');
$match_mom          =   $input->get('match_mom', null, 'RAW');
$match_toss         =   $input->get('match_toss', null, 'RAW');
$match_fow          =   $input->get('match_fow', null, 'RAW');
$match_comments     =   $input->get('match_comments', null, 'RAW');
$match_debutants    =   $input->get('match_debutants', null, 'RAW');
  • Yes sir that worked ! Commented May 15, 2015 at 12:02
  • Awesome, I missed that part @Lodder :) Commented May 15, 2015 at 12:09
  • Perfect answer, It worked like a charm Commented Oct 12, 2015 at 21:15
  • @DavidAddoteye - glad it helped ;)
    – Lodder
    Commented Oct 12, 2015 at 22:42
  • $input->get('match_mom', null, 'RAW') is good but not safe. you can use $input->get('match_mom', null, 'STRING') if you are passing strings in a form name or sentence. $input->get('match_id', null, 'INT') if you are passing integer. You can get full details of the filters here docs.joomla.org/Retrieving_request_data_using_JInput Commented Nov 3, 2015 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.