Welcome Guest, Not a member yet? Register   Sign In
Fatal error: Call to undefined function db_clean()
#1

[eluser]arjo[/eluser]
Hi,

I am trying to split the admin part from Claudia's kids sample shop to get to know CodeIgniter. I am getting along just fine so far but the function db_clean() causes a fatal error. I can leave it out but from safety point of view I would like to keep it in.

Here is a piece of code, placed in application\models\madmins.php where the function db_clean is used:

Code:
function addUser()
{
         $data = array('username' => db_clean($_POST['username'],16),
                    'email' => db_clean($_POST['email'],255),
                    'status' => db_clean($_POST['status'],8),
                    'password' => db_clean(dohash($_POST['password']),16)
                    );
    
      $this->db->insert('admins',$data);
    
}

Does anyone have a clue what is going on? I am using the same libraries that are used in the sample. And the original sample is working fine on the same webserver and mysql server. Is it a setting somewhere to enable the function? Can't wait...

Thanx Arjo
#2

[eluser]arjo[/eluser]
Found the problem, I was missing the file claudiaskids\shopping\system\application\helpers\MY_security_helper.php

content:
Code:
<?php
function id_clean($id,$size=11){
return intval(substr($id,0,$size));
}

function db_clean($string,$size=255){
return xss_clean(substr($string,0,$size));
}
?>
#3

[eluser]maria clara[/eluser]
hi,

may i ask a question?? what does your “db_clean” stands for?? because i have this script.
Code:
$fields = array(
                    'module_name'=>db_clean($_POST['module_name'],200),
                    'slug'=>db_clean($_POST['slug'],200),
                    'icon'=>db_clean($_POST['icon'],50),  
                    'file_name'=>db_clean($_POST['file_name'],100),          
                    'report_file_name'=>db_clean($_POST['report_file_name'],50),
                    'sql_select'=>db_clean($_POST['sql_select']),
                    'sql_filter'=>db_clean($_POST['sql_filter']),
                    'sql_order'=>db_clean($_POST['sql_order'])
                
                );

and the db_clean() got me an error in my console.
Quote:<br />
<b>Fatal error</b>: Call to undefined function db_clean() in <b>C:\xampp\htdocs\comunionerp\system\application\modules\at_reports\controllers\at_reports.php</b> on line <b>96</b><br />
i'm new to this function..can you please explain to me the function..

thanks in advance,
maria
#4

[eluser]arjo[/eluser]
you need the function db_clean wich is in the file system\application\helpers\MY_security_helper.php

if you don't have the file, this is the content:
Code:
&lt;?php
function id_clean($id,$size=11){
return intval(substr($id,0,$size));
}

function db_clean($string,$size=255){
return xss_clean(substr($string,0,$size));
}
?&gt;;


As you can see, db_clean is a function. It calls another function namely xss_clean. This function cleans up your data that you submit to the function. So the function db_clean is for cleaning up your data you are storing in a database.

greetz Arjo
#5

[eluser]maria clara[/eluser]
i have solved it already. thanks for your reply.

cheers,
kahtrina Wink
#6

[eluser]mact1079[/eluser]
I am still receiving the "Fatal error: Call to undefined function db_clean()" after putting in MY_security_helper.php. Any idea why? This my model code.

Code:
class Admins_model extends CI_Model{

function Admins_model(){
  parent::__construct();
}


function verifyUser($u,$pw){

  $this->db->select('id,username');
  $this->db->where('username',db_clean($u,16));
  $this->db->where('password', db_clean($pw),16);
  $this->db->where('status', 'active');
  $this->db->limit(1);
  $Q = $this->db->get('admins');

  if ($Q->num_rows() > 0){
   $row = $Q->row_array();
   $_SESSION['userid'] = $row['id'];
   $_SESSION['username'] = $row['username'];
  }else{
   $this->session->set_flashdata('error', 'Sorry, your username or password is incorrect!');
  }  
}

I tried adding also loading the helper with

Code:
function Admins_model(){
  parent::__construct();
  $this->load->helper('MY_security_helper');
}

but I receive error

"Unable to load the requested file: helpers/my_security_helper.php"
#7

[eluser]TWP Marketing[/eluser]
mact1079
Did you also create the helper file my_security_helper.php as shown in the prior post?
#8

[eluser]mact1079[/eluser]
Yes I have CIapplication/helpers/MY_security_helper.php with below

Code:
&lt;?php
function id_clean($id,$size=11){
return intval(substr($id,0,$size));
}

function db_clean($string,$size=255){
return xss_clean(substr($string,0,$size));
}
?&gt;
#9

[eluser]TWP Marketing[/eluser]
Did you load the helper library too, in your controller
$this->load->helper('security_helper');
#10

[eluser]mact1079[/eluser]
Seems like that was the issue. I was loading it with $this->load->helper(‘MY_security_helper’) not $this->load->helper('security_helper'); Thanks for pointing that out!




Theme © iAndrew 2016 - Forum software by © MyBB