Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"×" character breaking MySQL records

The "×" symbol (not a little x), I believe this is the multiplication symbol, is breaking MySQL records.

The problem is that whenever I try to retrieve a record that has this symbol "×" the record returns as blank.

I am using PHP and WAMP server by the way.

The collation is latin1_swedish_ci. However, changing collations didn't seem to fix the problem. The mysql version is 5.6.17 Here is my function that gets the records from the table and saves it to an object:

public function assign() {
    $SQL = "SELECT * FROM " . $this->tb . " ORDER BY " . $this->order;
    $this->tb_handle = mysqli_query($this->db_handle,$SQL);

    $this->rowNumber = mysqli_num_rows($this->tb_handle);

    //this creates arrays from records given even if the table is empty
    //this is to prevent errors
    if ($this->rowNumber === 0) {
        foreach ($this->records as $record) {
            $this->{$record} = array();
        } 
    } else {
        $i = 0;        
        while ( $db_field = mysqli_fetch_assoc($this->tb_handle) ) {
            foreach ($this->records as $record) {
                $this->{$record}[$i] = $db_field[$record];
                $this->{$record}[$i] = htmlspecialchars($this->{$record}[$i]);
            }            
            $i++;
        }
    }
}

This works for anything that does not have the "×" symbol. i don't know why that symbol should cause the entire record to return as blank.

like image 838
Zack Avatar asked Aug 22 '14 07:08

Zack


1 Answers

I see you use the htmlspecialchars until PHP 5.4 the internal encoding is UTF-8. So if you have a record with iso data and you put it in htmlspecialchars you get no result.

In this case you have to set the encoding to iso-8859-1 for example.

To solve the problem you can define an encoding

htmlspecialchars($value, ENT_QUOTES, "ISO-8859-1");

This will fix symbols showing incorrectly:

mb_convert_encoding($value, "UTF-8");

I think this could be your problem.

like image 194
René Höhle Avatar answered Sep 28 '22 01:09

René Höhle