php echo 来自带有断线的数据库
我相信这是一个简单的问题,但目前还无法弄清楚。 我有一个文本区域,提交后会转到数据库,然后我在页面上回显此文本,但问题是,假设该人在文本区域上写入:
嗨罗伯特,
这只是一个测试!。
杰森。
消息就这样发送到数据库,但是当我回显时,我得到:
嗨罗伯特,这只是一个测试!。 杰森。
这是形式:
<textarea name="newMessage" wrap="hard" cols="30" rows="3"></textarea>
<input type="submit" name="submit" value="Ingresar"> </>
这是我用来显示文本的代码:
<?php
while($row = mysql_fetch_assoc($messages)){
echo $row['mensaje']."<br/>";
}
?>
这是我用来插入代码的代码:
if(isset($_POST['submit'])){
$check4LB = $_POST['newMessage'];
while($letter = mysql_fetch_assoc($check4LB)){
if($letter=' '){
$letter='<br/>';
}
} /////I know this is not write bu is the idea i thgouht at least
$query = mysql_query("SELECT (ifnull(max(idRegistro),0) + 1) as id FROM messages");
$row = mysql_fetch_array($query);
$idMax = $row['id'];
$insertMessage = "INSERT INTO messages(idRegistro, mensaje) VALUES ('".$idMax."','".$letter."')";
mysql_query($insertMessage) or die(mysql_error());
echo "<meta http-equiv=Refresh content=\"0 ; url=".$_SERVER['PHP_SELF']."\">";
}
This is a simple question I believe, but can't figure it out yet.
I have a text area that after submit goes to a database, and then I echo this text on a page, but here is the problem, say the person writes on the textarea:
Hi Robert,
This is just a test!.
Jason.
And the message goes to the database just like that, but when I echo that, I get:
Hi Robert, This is just a test!.
Jason.
This is the form:
<textarea name="newMessage" wrap="hard" cols="30" rows="3"></textarea>
<input type="submit" name="submit" value="Ingresar"> </>
This is the code I use to display the text:
<?php
while($row = mysql_fetch_assoc($messages)){
echo $row['mensaje']."<br/>";
}
?>
This is what I use to insert the code:
if(isset($_POST['submit'])){
$check4LB = $_POST['newMessage'];
while($letter = mysql_fetch_assoc($check4LB)){
if($letter=' '){
$letter='<br/>';
}
} /////I know this is not write bu is the idea i thgouht at least
$query = mysql_query("SELECT (ifnull(max(idRegistro),0) + 1) as id FROM messages");
$row = mysql_fetch_array($query);
$idMax = $row['id'];
$insertMessage = "INSERT INTO messages(idRegistro, mensaje) VALUES ('".$idMax."','".$letter."')";
mysql_query($insertMessage) or die(mysql_error());
echo "<meta http-equiv=Refresh content=\"0 ; url=".$_SERVER['PHP_SELF']."\">";
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试 echo nl2br($row['mensaje']);
try
echo nl2br($row['mensaje']);
对数据库的输出使用
nl2br()
。Use
nl2br()
on the output from the database.试试这个
Try this