Welcome Guest, Not a member yet? Register   Sign In
database INSERT and UPDATE converts symbols to html code
#1

(This post was last modified: 03-10-2016, 09:37 AM by webmachine.)

I have a registration form. If I enter a word such as can't, the INSERT and UPDATE functions replace the ' with  in the database.

It will display fine, but if I populate the form with database entries in order to edit the information, the field shows
can't with the html code for ' instead of the ' .

If I then re-submit the form after editing, the html code for '  is replaced by & and the html code for '  in the database, and so on. 


This is really bad for the user. Besides I don't want the html code
for ' to be stored in the database, I want the actual word can't. What can I do to prevent this?
Reply
#2

(This post was last modified: 03-10-2016, 09:36 AM by keulu.)

your table need to be collate utf8_general_ci.
your files encoding UTF-8 too
add <meta charset="UTF-8"> in your layout

is that good for you ?
Reply
#3

(This post was last modified: 03-10-2016, 09:41 AM by webmachine.)

(03-10-2016, 09:35 AM)keulu Wrote: your table need to be collate utf8_general_ci.
your files encoding UTF-8 too
add <meta charset="UTF-8"> in your layout

is that good for you ?

Thanks for answering so quickly. I'll try that now.
Reply
#4

The text is being insert properly in the database now, and it is being displayed properly, but when I pre-populate the form for editing, the ' is still being converted. Why is that?
Reply
#5

(This post was last modified: 03-10-2016, 10:05 AM by keulu.)

strange...

did you try with a new insert ? or editing an old entry ?

a simple html_entity_decode() work, but you maybe have a more deep problem...
Reply
#6

(This post was last modified: 03-10-2016, 10:43 AM by Narf.)

CI doesn't do such conversions unless you tell it to ... stop using global_xss_filtering, xss_clean() (you probably have that as a form validation rule), etc. on your inputs.
Reply
#7

(This post was last modified: 03-10-2016, 12:59 PM by webmachine.)

I am still having the problem with populating my form for editing. I have changed everything to utf8. I am only using standard rules in my form validation such as required, and Regex's. Where else can I look?

The words are being inserted into my database fine, and displayed on the page fine - just the populating of the form for editing is a problem.

In my config file, I have $config['global_xss_filtering'] = FALSE;
Reply
#8

Then you're somehow doing HTML escaping while populating your forms.
Reply
#9

(This post was last modified: 03-11-2016, 07:35 AM by webmachine.)

This is the code I use for the form:

PHP Code:
<div class="form-control">
 
    <?php echo form_label('Last Name: ''last_name'); ?><br />
     <?php
          $attributes 
= array(
 
              'id' => 'last_name',
 
              'name' => 'last_name',
 
              'value' => set_value('last_name'$client->last_name)
 
         );
 
        echo form_input($attributes);
 
    ?>
</div> <!-- end of .form-control --> 

In my controller, this is the only validation rule I am using for this input:
PHP Code:
$this->form_validation->set_rules('last_name''<span>"Last Name"</span>''required'); 

This is where I get $client:
PHP Code:
'client' =>$this->registration_model->get_single_client($_SESSION['client_id']),   

And this is in my model:
PHP Code:
/*
* get a specific client
*/
 
public function get_single_client($client_id) {
 
 
$this->db->where('id'$client_id);
 
$query $this->db->get('clients');
 
 return 
$query->row();
 
 } 

Where in any of this code am I doing HTML escaping?
Reply
#10

You're actually doing it twice - once with form_input() and once with set_value() - resulting in double encoding.

form_input() will always apply HTML escaping, and that's fine - that's how it is supposed to work.
But you're passing it a value that was already escaped by set_value(), so now the '&amp;' becomes '&amp;amp;' ...

http://www.codeigniter.com/userguide3/he...#set_value
Reply




Theme © iAndrew 2016 - Forum software by © MyBB