我仍然是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)。 –