【发布时间】:2014-03-05 21:59:24
【问题描述】:
我有一个 HTML 表单。当您单击提交按钮时,它会将框中的数据存储到表格中,然后显示一条消息。消息从 PHP 文件发送,然后由 js 在 HTML 文件中显示。问题是消息中有br 标签,当显示消息时,它显示<br> 标签而不是换行。
这是我正在测试它的地方 - http://ft5.cu.cc/ 点击心脏标志查看表格。
HTML 表单
<div class="contact">
<form method="post" action="daalo.php">
<input type="text" maxlength="30" class="text" name="ign" id="ign" placeholder="Please type your IGN(In Game Name)" required="required"/>
<input type="email" maxlength="30" class="required email" name="email" id="email" placeholder="Please type your email" required="required"/><span class="status"></span>
<table width="100%">
<tr>
<td><input type="text" maxlength="30" class="text" id="steamid" name="steamid" placeholder="Enter your Steam ID" required="required"/></td>
<td><span class="status">
<img id="tick" alt="Good"src="images/tick.png" width="16" height="16"/></td>
</tr>
</table>
<span id="cross">Steam Id Already Added</span>
</span>
<input type="submit" name="register" id="register" value="Submit" disabled="disabled" />
</form>
<div id="loading">Processing your <b>WHITELIST</b> entry....</div>
<div id="success"></div>
</div>
*PHP 插入*
<?php
include('connecti.php'); //Ganja Login
// Check connection
if (mysqli_connect_errno())
{
echo 'Failed to connect to MySQL: ' . mysqli_connect_error();
}
//Insert
$lab1='IGN<br>';
$lab2='Email ID<br>';
$lab3='Steam ID<br>';
$lab4='Submitted.';
$lab5='Whitelist is updated everyday at 8pm (UTC+01:00) Brussels, Copenhagen, Madrid, Paris.';
$sql="INSERT INTO rusty_whitelist (name, email, steamid) VALUES ('$_POST[ign]','$_POST[email]','$_POST[steamid]')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo $lab1;
echo $lab2;
echo $lab3;
echo $lab4;
echo $lab5;
mysqli_close($con);
?>
Java 脚本
(function($) {
$('form').submit(function(e){
var thisForm = $(this);
e.preventDefault();
$(this).fadeOut(function(){
$("#loading").fadeIn(function(){
$.ajax({
type: 'POST',
url: thisForm.attr("action"),
data: thisForm.serialize(),
success: function(data){
$("#loading").fadeOut(function(){
$("#success").text(data).fadeIn();
});
}
});
});
});
});
$('.md-trigger').tipsy({gravity: 's'});
})(jQuery);
$(function(){
$().ready(function() {
$('#videobg').tubular({videoId: 'tDvBwPzJ7dY'}); // where idOfYourVideo is the YouTube ID.
});
});
【问题讨论】:
-
我清理了您的问题以正确格式化。请阅读how to format your posts。无论如何,我认为您没有向我们提供有关您如何显示此内容的足够信息。我们无法回答,因为您没有向我们展示任何代码。
-
是的,我正试着把它放进去,现在它不让我这么做。我也试过这种方式 '$lab1='IGN
';' '$lab2='电子邮件ID
';'然后在插入'echo $lab1;'之后'回声 $lab2;' -
我在 cmets 中发布了它,但它似乎没有正确显示,并且不允许我再编辑它
-
这不是我说的代码。我说的是执行输出的 PHP 和处理它的 JS。
-
旁注:您的数据库也是
Open to SQL injection;使用准备好的语句。
标签: javascript php jquery html line-breaks