php 论坛在提交时未检测到新行

标签 php mysql forms newline forum

我正在尝试设置一个与论坛非常相似的功能,用户可以在其中编写章节或故事(长段文本)。然后,该文本将存储在 mysql 上,以便可以调用、阅读和评论等。这一切都已设置并且工作正常,但是当用户键入新行时,它无法被识别。所以用户可以输入 -

这是第 1 段

这是第 2 段

但是显示的只是 -

这是第 1 段这是第 2 段

我知道有一些字符是html和php,例如

或\n,但是使用论坛的人不会足够聪明来做到这一点。有什么办法可以让它自动工作吗?

下面是我的 add_topic.php 的代码

<?php
session_start();
$uname = $_SESSION['uname'];



$host="mysql.******************.co.uk"; // Host name 
$username="**********"; // Mysql username 
$password="************"; // Mysql password 
$db_name="************_members"; // Database name 
$tbl_name="forum_question"; // Table name 

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// get data that sent from form 
$topic=$_POST['topic'];
$detail=$_POST['detail'];
$name=$_POST['username'];
$datetime=date("d/m/y h:i:s"); //create date time

$sql="INSERT INTO $tbl_name(topic, detail, name, datetime)VALUES('$topic', '$detail', '$name', '$datetime')";
$result=mysql_query($sql);

if($result){
echo "Successful<BR>";
echo "<a href=main_forum.php>View your topic</a>";
}
else {
echo "ERROR";
}
mysql_close();
?>

当前数据库上的“详细信息”字段设置为 MidText。我也尝试过 MidBlob 但结果没有变化。

以下是我的create_topic.php代码-

<?php
  session_start();
$uname = $_SESSION['uname'];
  ?>

<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form id="form1" name="form1" method="post" action="add_topic.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3" bgcolor="#E6E6E6"><strong>Create New Story</strong> </td>
</tr>
<tr>
<td width="14%"><strong>Title</strong></td>
<td width="2%">:</td>
<td width="84%"><input name="topic" type="text" id="topic" size="50" /></td>
</tr>
<tr>
<td valign="top"><strong>Story</strong></td>
<td valign="top">:</td>
<td><textarea maxlength="2000000" name="detail" cols="50" rows="30" id="detail"></textarea></td>
</tr>
<tr>
<td><strong>Username</strong></td>
<td>:</td>
<td><input name="username" value="<?php echo $uname; ?>" type="text" id="username" size="50" readonly></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Submit" /> <input type="reset" name="Submit2" value="Reset" /></td>
</tr>
</table>
</td>
</form>
</tr>
</table>

我是一个绝对的初学者,但我会尽力提出任何可以提供的建议或故事。如果您需要更多信息,请告诉我。

提前非常感谢。

最佳答案

您是否尝试过使用 nl2br显示前?它将改变所有\n字符转html <br/> .

另请参阅文档:http://php.net/manual/en/function.nl2br.php

关于php 论坛在提交时未检测到新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20311551/

相关文章:

mysql - 选择多列并将其设置为 DTO 列表

php - 如何在 Symfony 表单中创建作为 SubmitType 子级的自定义 SaveType

forms - 将MailChimp订户添加到具有注册表单而不是API的组中

php - 无法获取缓存的 Kerberos 票证

php - 正则表达式适用于 Javascript 但不适用于 PHP preg_match

php - 最佳实践 : handle class error

php - 使用 PHP 存储用户输入数据 24 小时

php - Woocommerce 新用户邮箱

mysql - PreparedStatement 是否将空字符串转换为 null?

mysql - Ruby 中的绑定(bind)变量