我仍然是PHP的初学者,但我需要某些帮助。我有一个日期格式的评论,我试图插入一个“时间以前”的格式。我遇到了麻烦。这是代码:日期格式时间前
<?php
$name = mysql_real_escape_string($_POST['name']);
$comment = mysql_real_escape_string($_POST['comment']);
$submit = $_POST['submit'];
$date = date("M jS Y | g:i a T");
$ip = "".$_SERVER['REMOTE_ADDR']."";
if($submit)
{
if($name&&$comment)
{
$query=mysql_query("
INSERT INTO comment (id, articleid, name, comment, date, ip) VALUES ('','". mysql_real_escape_string($_GET['id']) ."','$name','$comment','$date','$ip')
");
header("Location: " . mysql_real_escape_string($_GET['id']) . "");
}
else
{
echo "<div class='red'>You must fill in all fields!</div>";
}
} >
这里的输出:
<div class="article-body">
<div class="user"><b><?php echo $row['name'] ?></b> <span>says:</span></div>
<div class="comments">
<?php echo $row['comment'] ?> <br /><p></p>
<p style="font-size:12px;">Posted on <b><?php echo $row['date'] ?></b></p>
</div>
</div>
我尝试用谷歌与一对夫妇代码摆弄,但没有成功,因为我一个noob。哈哈。
这方面的任何东西?
谢谢!
为什么你会在MySQL中使用它之前逃避一些东西?这是没有意义的。另外,如果在HTML/XHTML的上下文中使用htmlspecialchars()时不包含可变数据,那么您将拥有一个很好的XSS漏洞。 – Brad
“我还是PHP的初学者” 这就是说,这是一个常见的初学者/没有经验的人的错误,以逃避一切。 – Steve
[**请不要在新代码中使用'mysql_ *'函数**](http://bit.ly/phpmsql)。他们不再被维护,[弃用过程](http://j.mp/Rj2iVR)已经开始。看到[**红框**](http://j.mp/Te9zIL)?学习[*准备的语句*](http://j.mp/T9hLWi),并使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli) - [这篇文章](http://j.mp/QEx8IB)将帮助你决定哪个。如果你选择PDO,[这里是一个很好的教程](http://j.mp/PoWehJ)。 –