English 中文(简体)
准绳 网址:MySQL PHP
原标题:Allow Line Breaks in a php chat - MySQL PHP

我建立了非常简单的聊天系统......它发挥了巨大作用,当用户输入正确显示的信息时,唯一的问题是线断线不显示。

I am thinking I need to convert 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)

我的法典载于聊天。 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>
最佳回答

http://php.net/nl2br>。

问题回答

暂无回答




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签