Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6832779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:54:00+00:00 2026-05-26T22:54:00+00:00

I built a very simple chat system… it works great and when the user

  • 0

I built a very simple chat system… it works great and when the user enters a message it displays properly, the only problem is that line breaks don’t show up…. somewhere along the line of sending the info to the database and retrieving it I lose the line breaks…

I am thinking I need to convert \n to <br> somewhere along the way but I really don’t know much about this type of coding… I’ve mostly done games and stuff… No websites or database coding until today (my first day)

Here is my code found on chat.php

<html><head></head><body>
<form action="chat.php" method="post">
Message: <br><textarea type="text" name="message" style="width:80%; height:300px;"></textarea><br>
<input type="submit" />
</form>
<div style="width:100%;">

<?php

$host="***";
$user="***";
$password="***";

$cxn = mysql_pconnect ($host, $user, $password);

mysql_select_db("defaultdb", $cxn);

if (getenv(HTTP_X_FORWARDED_FOR)) {
    $ipaddress = getenv(HTTP_X_FORWARDED_FOR);
} else {
    $ipaddress = getenv(REMOTE_ADDR);
}

$message = strip_tags($_POST["message"]);

mysql_query("INSERT INTO ChatTest (ID, TimeStamp, Message) VALUES ('$ipaddress', NOW(), '$message')");

$data = mysql_query("SELECT * FROM ChatTest ORDER BY TimeStamp DESC") or die(mysql_error()); 
 Print "<table border cellpadding=3 width='100%' style='table-layout:fixed'>
        "; 
 Print "<tr>"; 
 Print "<th style='width:10%;'>ID:</th><th style='width:10%;'>TimeStamp:</th><th style='width:70%;'>Message:</th>";
 while($info = mysql_fetch_array( $data )) { 
 Print "
        <tr>"; 
    Print " <td>".$info['ID'] . "</td> "; 
    Print " <td>".$info['TimeStamp'] . " </td>";
    Print " <td style='white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word'>".$info['Message'] . "</td></tr>
            "; 
 } 
 Print "</table>"; 

mysql_close($cxn);


?>

</div></body></html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:54:01+00:00Added an answer on May 26, 2026 at 10:54 pm

    Use nl2br() to convert plain linebreaks to html linebreaks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple chat system I've built using PHP and MySQL (this
I just built a very simple add-on for Firefox, but it's only compatible with
I've built a very simple chatroom-like ASP.NET application which displays current Online/Offline users: I
I have built a very simple internal messaging system inside my application, i want
For my personal website, I built a very simple dropdown menu system entirely from
I have built a very simple blog application using Ruby on Rails. New to
I built a very simple app using a PHP form with a bit of
I built a (very simple) library, which I can call just fine from another
Here's my situation; I've built a very simple web app that looks up a
I have built a variety of little scripts using Ruby's very simple Queue class,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.