-2

A user inserts a message into the database, then I SELECT the message and do a echo to put the message in the div. For some reason the text is going over the right border of the div

I tried using a blockquote and it worked with a random text that W3Schools had there and when I put the echo inside the blockquote it happens anyway. See on the prints:

enter image description here

The parts from the code:

<?php
$sql_post = "SELECT `dataTopico`,`username`,`titulo`,`mensagem` FROM `".$bd."` WHERE `idTopico`='$id_topico'";
$exePost = mysql_query($sql_post);
$post=mysql_fetch_array($exePost);
?>

<blockquote>
    WWF has been protecting the future of nature. The world 
    leading conservation organization, WWF works in 100 countries and is 
    supported by 1.2 million members in the United States and close 
    to 5 million globally.
</blockquote>

<blockquote>
    <?php echo $post['mensagem'];?>
</blockquote>

The query is right; it gets the test message but the text goes over the borders. I want it to go down like the text above.

Stickers
  • 75,527
  • 23
  • 147
  • 186
Brunaine
  • 1,178
  • 2
  • 16
  • 24
  • you did close off your php before going into pure html, right? there's also not enough code to support the question, seeing there's a border in there and you mention `
    `, what div?
    – Funk Forty Niner Jan 07 '17 at 21:30
  • Every time you use [the `mysql_`](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) database extension in new code **[a Kitten is strangled somewhere in the world](http://2.bp.blogspot.com/-zCT6jizimfI/UjJ5UTb_BeI/AAAAAAAACgg/AS6XCd6aNdg/s1600/luna_getting_strangled.jpg)** it is deprecated and has been for years and is gone for ever in PHP7. If you are just learning PHP, spend your energies learning the `PDO` or `mysqli` database extensions. [Start here](http://php.net/manual/en/book.pdo.php) – RiggsFolly Jan 07 '17 at 21:31
  • Fred , yeah i did i just resume the code – Brunaine Jan 07 '17 at 21:32
  • and where are all those a's coming from? sorry but this question is way too unclear for *moi*. – Funk Forty Niner Jan 07 '17 at 21:33
  • Riggs, im doing a project on School , i learned Mysql i need to use it , i know mysqli but i will be using it in future projects/works. – Brunaine Jan 07 '17 at 21:33
  • @RiggsFolly yeah, I asked them earlier where they were closing the php tag here and injecting pure html; gotta run now. – Funk Forty Niner Jan 07 '17 at 21:34
  • Riggs , but that color is not affecting when i dont have that there it still doenst work , if i put a random text it works well the thing is the Message that comes from the DB it doesnt break down – Brunaine Jan 07 '17 at 21:34
  • Ok im gonna resume , im doing a Forum , so i did the page to creat a Post on the Forum and this is going to show the message , im just testing with a Div thats all nothing designed but when i saw that the Message goes over the border i didn't know what to do. The aaaa... is just a test created to show if a big text is there it does this problem. – Brunaine Jan 07 '17 at 21:37
  • Fred, @RiggsFolly the guy down there solved it out for me, thank you anyway guys, sorry about the format, i was in a rush ! – Brunaine Jan 07 '17 at 21:41

1 Answers1

2

You can break a word that is too long for the container with the CSS word-wrap property.

blockquote {
  width: 200px;
  border: 1px solid black;
}

.solution {
  word-wrap: break-word;
}
Blockquote with default word-wrap value (normal):

<blockquote>
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
</blockquote>

Blockquote with the word-wrap property set to break-word:

<blockquote class="solution">  
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
</blockquote>
Marvin
  • 9,164
  • 3
  • 26
  • 44
  • It worked , thank you very much for the quick answer on this now I can make the box how I want , really thank you! http://prntscr.com/dsrjtd – Brunaine Jan 07 '17 at 21:39