Welcome Guest, Not a member yet? Register   Sign In
codeigniter issues with DB and special characters
#1

Hi guys

i am using an app in php which was designed and using codeigniter 1.7.xx version i think

i have an issue regarding charset and i am kind of lots perhaps someone might help me

i am tryint to find for URLencode and decode functions on codeigniter.


i have an issue regarding the following plaintext which gets stored on my mysql db as special character.


so first things first


on codeignite i have setup my db  charset on  UTF-8



config.php
$config['charset'] = "UTF-8";




database.php
$db['default']['char_set'] = "utf8";

$db['default']['dbcollat'] = "utf8_general_ci";



also i have tried db  with latin1 and latin1_general_ci


and on mysql db in have all sql db now changed to utf8_genral_ci  and i have also tested in in latin1

my problem is the following

i have a config webgui page in php

which collects the input data for a autoconfiguration file it gets generated..

this autoconfiguration options is an option which selects specific data unique from each device tunner

so this is my config example


Auto_ipv4 = 239.106.%card.%number


this %card and %number are data input from specific hardware unique data..


on my device console it works great..


but on the webgui php when i press write to store this on the database it gets stored as  239.106.?rd.%number

because it classifies this %ca  as special character ?


so how can i changet this in order to make it interpreter as a simple text input data to store it on my mysql db ?


is there a solution for this? i am kind of lost any help would be appreciated..


i have the folloowing code on /controllers

config.php

PHP Code:
<?php
/**
 
 */

class Config extends Controller {
 
   public function __construct() {
 
       parent::Controller();
 
       $this->load->model('config_model');
 
       $this->load->helper('form');
 
       $this->load->library('form_validation');
 
       $this->load->helper('url');
 
       $this->load->database();
 
   }

 
   public function index($status=''$type='') {
 
       $data['all'] = $this->config_model->findAll();
 
       if ($status != ''$data['user_msg']['status'] = $status;
 
       if ($type != ''$data['user_msg']['type'] = $type;
 
       
        $this
->load->view('header');
 
       $this->load->view('navigation');
 
       $this->load->view('config/index'$data);
 
       $this->load->view('footer');
 
   }
 
   
    
    
public function edit($id$status='') {
        if (
$status == '' OR $status == 'error') {
            
$data['config'] = $this->config_model->find($id);
            
$this->load->view('header');
 
           $this->load->view('navigation');            
            
$this->load->view('config/edit'$data);
            
$this->load->view('footer');
        }
        elseif (
$status == 'valid') {
            
$this->setValidation();
     
       if ($this->form_validation->run() == true) {
     
           $data['value'] = $this->input->post('value'true);
 
   
                $this
->config_model->update($id$data);
     
           redirect('config/index/success/form');
     
       }
     
       else {
     
           redirect('config/edit/'.$id.'/error');
     
       }
        }
 
   }
 
   
    public 
function setValidation() {
 
       $this->form_validation->set_rules('value''Valeur''required');
 
   }







This is the export.php code

PHP Code:
<?php
/**
 
 */

class EXPORT extends Controller {
 
   public function __construct() {
 
       parent::Controller();
 
       $this->load->model('config_model');
 
       $this->load->model('tuner_model');
 
       $this->load->model('chaine_model');
 
       $this->load->helper('form');
 
       $this->load->library('form_validation');
 
       $this->load->helper('url');
 
       $this->load->database();
 
   }

 
   public function index($status=''$type='') {
 
       $data['config'] = $this->config_model->findAll();
 
       $data['transponder'] = $this->tuner_model->findByIsActive();
 
       $data['chaine'] = $this->chaine_model->findAll();
 
       $this->load->view('header');
 
       $this->load->view('navigation');
 
       $this->load->view('export/index'$data);
 
       $this->load->view('footer');
 
   }
 
   
    public 
function send() {
 
       exec('sudo /etc/init.d/portalnetheadend2 stop');
 
       $path '/etc/portalnetheadendconfig';
 
       $opath opendir($path);
 
       while ($f readdir($opath)) {
 
           if (substr($f, -5) == '.conf') {
 
               unlink($path.'/'.$f);
 
           }
 
       }
 
       
        
for ($i=1$i <= $this->input->post('nb_file'true); $i++) {
 
           //echo $this->input->post('nb_file', true);
 
           //echo $this->input->post('exportfile-'.$i, true);
 
           //echo $this->input->post("export-2", true);
 
           $handle fopen($path.'/'.$this->input->post('exportfile-'.$itrue), 'w');
     
       fwrite($handle$this->input->post('export-'.$itrue));
     
       fclose($handle);
 
       }
 
       exec('sudo /etc/init.d/portalnetheadend2 start');
 
       $this->load->view('header');
 
       $this->load->view('navigation');
 
       $this->load->view('export/send');
 
       $this->load->view('footer');
 
   }

And this is the view and edit php files
PHP Code:
<?php if (isset($user_msg['status'])): ?>

    <div class="flashbox <?=$user_msg['status']?>">
        <?php if ($user_msg['status'] == 'success' && $user_msg['type'] == 'form') echo "Os parametros de configuração foram alterados com sucesso.";?>
        <?php if ($user_msg['status'] == 'error' && $user_msg['type'] == 'form') echo "Não foi possivel modificar os parametros de configuração.";?>
    </div>
<?php endif; ?>

    <br/>
    <?=form_open('config/edit/'.$config->id.'/valid')?>
    <table class="form">
        <tr>
            <th>Configurar parametros</th>
            <td><?=$config->name?></td>
            <td><input type="text" name="value" value="<?=$config->value?>" /></td>
        </tr>
        
        <tr>
            <td colspan="2"><input type="submit" value="Gravar"/></td>
        </tr>
    </table>
    <?=form_close()?>

PHP Code:
<?php if (isset($user_msg['status'])): ?>
    <div class="flashbox <?=$user_msg['status']?>">
        <?php if ($user_msg['status'] == 'success' && $user_msg['type'] == 'form') echo "Os parametros de configuração foram alterados com sucesso.";?>
        <?php if ($user_msg['status'] == 'error' && $user_msg['type'] == 'form') echo "Não foi possivel alterar os parametros de configuração.";?>
    </div>
<?php endif; ?>

    <table class="table" cellspacing="0" accept-charset="UTF-8">
        <tr>
            <th>Parametros</th>
            <th>Valores</th>
            <th>Editar</th>
        </tr>
        <?php foreach($all as $item): ?>
        <tr>
            <td><?=$item->name?></td>
            <td><?=$item->value?></td>
            <td><a href="<?=site_url('config/edit/'.$item->id)?>"><img src="<?=base_url()?>/css/icon/pencil.png" title="Gravar"/></a></td>
        </tr>    
        <?php endforeach; ?>
    </table> 

Basically i just need to store this data without beeing fetched as special character  just as plain text.

any help will be appreciated 

Thxs
PortalNET
Reply
#2

Hiya

Looks like this is the part where i need to check first the plain text to avoid storing it as special character


Quote:elseif ($status == 'valid') {
$this->setValidation();
       if ($this->form_validation->run() == true) {
        $data['value'] = $this->input->post('value', true);
   
           $this->config_model->update($id, $data);
           redirect('config/index/success/form');
       }
       else {
           redirect('config/edit/'.$id.'/error');
       }
}
Reply
#3

Ok so far i have tested and found this is the problem with this special char

%ca , it output and stores it on my mysql as ?

and when i try to make the output of it from mysql it stores it also on the value as ?

instead of %ca any ideas or help on this

i have my db mysql and all codeigniter config set to UTF-8 and db utf8_unicode_ci and also teste on uft8_general_ci
Reply
#4

try escaping it ( \%ca or \\%ca )

See if that will work for it.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

(05-09-2018, 03:17 AM)InsiteFX Wrote: try escaping it ( \%ca or \\%ca )

See if that will work for it.


hiya 

i am kind of lost, where do i need to input the escape character?  in the controllers?
Reply
#6

In your sql queries.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#7

(05-10-2018, 04:20 AM)InsiteFX Wrote: In your sql queries.

yup i have added the escap string in the sql driver..

PHP Code:
// escape LIKE condition wildcards
        
if ($like === TRUE)
        {
            
$str str_replace(array('%''_''%ca'), array('\\%''\\_''\\%ca'), $str);
        }
        
        return 
$str


after saved, i reboot the db,  and when i insert 239.106.%card.%number

and save the txt data into my db it not stores only 239.106 no other data copied into the db

so it completelly wipes the data %card.%number
Reply
#8

(This post was last modified: 05-11-2018, 03:35 AM by InsiteFX.)

Not in the sql driver in the sql query that you create to send to the database.

Try with one / or two //

Also did you try doing this?

CodeIgniter User's Guide - Escaping Queries
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB