0
<?php
        require ('sql_connect.php');

        $query = "select * from `products`";
        $result = mysql_query($query);

        while($row = mysql_fetch_array($result))
        {
            $imagem = $row['imagem'];
            $texto = $row['texto'];

            echo "<img src=Images/Products/$imagem> <br> $texto";
        }
        ?>

I have the image and the text of the image that i want to show in my database.

I show the image but i have problems with the text... The text dont show the ENTERS/SPACES. There are some ways to resolve this?

Image of problem: https://i.stack.imgur.com/f51Pp.png

I want this: https://i.stack.imgur.com/f51Pp.png#1

Database: utf8_general_ci

In database text is saving with enters/spaces...

Isaac Bennetch
  • 11,830
  • 2
  • 32
  • 43
rubcpires
  • 13
  • 5
  • check what it is saving in DB for the field `texto`. Is it saving with spaces/enters/accented character? – prava Jun 05 '14 at 08:45
  • Its saving with enters/spaces... – rubcpires Jun 05 '14 at 08:53
  • possible duplicate of [Garbled UTF-8 characters in PHP](http://stackoverflow.com/questions/24042950/garbled-utf-8-characters-in-php) – Isaac Bennetch Jun 05 '14 at 15:57
  • possible duplicate of [Preserve Line Breaks From TextArea When Writing To MySQL](http://stackoverflow.com/questions/5048849/preserve-line-breaks-from-textarea-when-writing-to-mysql) – Petr R. Jun 05 '14 at 18:26

1 Answers1

0

maybe something is wrong on the encoding of connection. in that sql_connect.php file, after you connect, please execute this one:

mysql_query("SET NAMES 'utf8'");

if this doesn't help, try this one:

mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'", $conn);

where $conn is your connection. This will make sure everything is UTF-8

Also please make sure the column on your tables are utf8_general_ci

After all this, please re-enter your data to your db and try again.

Sharky
  • 6,154
  • 3
  • 39
  • 72