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