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 9120331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:36:13+00:00 2026-06-17T05:36:13+00:00

i have written a function for insertion into my database. i have a small

  • 0

i have written a function for insertion into my database. i have a small doubt .

Is my below code provides good security to escape my data before submitting it into my database?

Please suggest me some solution for this if the below code does not provide good way of insetion of data into db
views.php

 <? echo form_open('Setups/subject'); ?> 
                 <? echo '<div id="level">'. $subjectname.' : '.form_input($fsubjectname); ?>  
                 <?  echo form_submit($submitbtn); 
                  echo form_reset($resetbtn);  
                  echo '</fieldset>'; ?>

   <? echo form_close(); ?>    

controller.php

class Setups extends CI_Controller  {

function subject(){
    $this->load->helper('form'); 
    $this->load->model('Setupsmodel');

    if($this->input->post('subsubmit')){
        $this->Setupsmodel->entry_insert();
    }

    $data=$this->Setupsmodel->subjectsetup(); 
    $this->load->view('admin/setups/subject_setups',$data); 
  }
}

model.php

  class Setupsmodel extends CI_Model {

  function __construct()
{
    // Call the Model constructor
    parent::__construct();
}

function subjectsetup()
{
 $data['subjectname']='Enter Subject Name';  
 $data['fsubjectname']=      
  array('name'=>'subject_name','class'=>'input','size'=>30,'id'=>'txtsubject'); 

 $data['formtopic']='Subject Details Form';


 $data['submitbtn'] = array(
'name' => 'subsubmit',
'class' => 'button',
'value' => 'Submit',
'type' => 'submit',
'content' => 'Submit'

 );
  $data['resetbtn'] = array(
'name' => 'button',
 'class' => 'rsetbutton',
'value' => 'Reset',
'type' => 'reset',
'content' => 'Reset'
);

 return $data;   
}

//--------------Insertion of new record in the table subjectdetails into the db------------

function entry_insert(){
   $this->load->database();
   $data=array(
       'subject_name'=>$this->input->post('subject_name'));
$this->db->insert('subjectdetails',$data);
}   
} 
  • 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-17T05:36:14+00:00Added an answer on June 17, 2026 at 5:36 am

    You are not filtering your user input, so it’s risky. Anyways, CodeIgniter comes with a Cross Site Scripting Hack prevention filter which can either run automatically to filter all POST and COOKIE data that is encountered, or you can run it on a per item basis. By default it does not run globally since it requires a bit of processing overhead, and since you may not need it in all cases. To filter data through the XSS filter you can use following method from security class

    $data = $this->security->xss_clean($data);
    

    If you want the filter to run automatically every time it encounters POST or COOKIE data you can enable it by opening your application/config/config.php file and setting this

    $config['global_xss_filtering'] = TRUE;
    

    If you use the form validation class, it gives you the option of XSS filtering as well, using set_rules method of form validation class.

    $this->form_validation->set_rules('input_name', 'input label', 'xss_clean');
    

    So in this case, you can use in your controller

    $this->form_validation->set_rules('subject_name', 'Subject Name', 'xss_clean|required');
    if($this->form_validation->run())
    {
        $this->Setupsmodel->entry_insert();
    }
    

    There xss_clean rule will filter the input and required rule will check whether the input is empty or not, so if validation is successful then your insert method will work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am have written the following code below to encode a bitarray into custom
I have written a function that sorts a big scale of data. To test
I have written a function below: void trans(double x,double y,double theta,double m,double n) {
I have written a function to print database table to an array like this
I have a MySQL singleton class written in PHP. Its code is listed below:
I have this following code: $(window).load(function() { $('#content1').load('database.php'); setInterval (function() { $.post('status.php', { id:
i have written a code for insertion sort but it is nt sorting.. kindly
I've recently written a custom API for inserting data into my database from multiple
I have written a function to convert a date into a Unix time stamp.
I have written a function that extract the domain from hostname. e.g. www.domain.com ->

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.