我對PHP相當陌生,最近遇到了問題。評論框問題;數據未在網站上呈現
我在我的網站上使用PHP和MySQL創建了一個評論框,它工作正常,但有一個主要問題。該評論僅在網站上呈現/存儲在數據庫中,當它適合html評論框的一行時。每當我輸入更長的文本,它根本不會保存任何東西。
這裏是我使用的代碼:
<?php
mysql_connect("localhost","x","x");
mysql_select_db("fendersh_cdreviews");
$name=$_POST['name'];
$comment=$_POST['comment'];
$submit=$_POST['submit'];
$dbLink = mysql_connect("localhost", "x", "x");
mysql_query("SET character_set_client=utf8", $dbLink);
mysql_query("SET character_set_connection=utf8", $dbLink);
if($submit)
{
if($name&&$comment)
{
$insert=mysql_query("INSERT INTO cdreviews (name,comment) VALUES ('$name','$comment') ");
}
else
{
echo "please fill out all fields";
}
}
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<form action="cds.php" method="POST">
<table style="margin-left:15px; background-color:none; border-top: 1px dotted black; border-bottom: 1px dotted black; padding-bottom:5px;">
<tr><td><p style="margin-bottom:-20px;">Name:</p> <br><input type="text" name="name"/></tr>
<tr><td colspan="2"><p style="margin-bottom:-5px;">Comment:</p> </td></tr>
<tr><td colspan="5"><textarea name="comment" rows="3" cols="50"></textarea>
<tr><td colspan="2"><input type="submit" name="submit" value="Comment"></td></tr>
</table>
</form>
<?php
$dbLink = mysql_connect("localhost", "x", "x");
mysql_query("SET character_set_results=utf8", $dbLink);
mb_language('uni');
mb_internal_encoding('UTF-8');
$getquery=mysql_query("SELECT * FROM cdreviews ORDER BY id DESC");
while($rows=mysql_fetch_assoc($getquery))
{
$id=$rows['id'];
$name=$rows['name'];
$comment=$rows['comment'];
echo "<p><b>$name</b>; $comment </p>"
;}
?>
我有出於安全原因的X替換user_name和密碼。
這就是我使用的代碼,它工作正常。
它連接到數據庫好吧;我已將我的列參數設置爲TEXT。
有什麼我應該改變嗎?
希望有人可以幫助我進一步與此。
問候
傑克
您正在使用[**的**過時的數據庫API(http://stackoverflow.com/ q/12859942/19068),並應使用[現代替代](http://php.net/manual/en/mysqlinfo.api.choosing.php)。你也**易受[SQL注入攻擊](http://bobby-tables.com/)**,現代的API會使[防禦]更容易(http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php)自己從。 – Quentin
除了這個巨大的SQL安全問題,您的應用程序也容易受到XSS攻擊。 – PeeHaa