2013-06-23 30 views
1

我有问题,我可以连接到我的数据库,但它不会保存在数据库中,我在文本区域中写了什么。每次我点击更新它保存为空白,如果我直接在MySQL中写lalala并刷新文本区域的页面,我可以在文本区域看到lalala,但如果我替换文本区域中的文本lalala作为其他内容并单击更新,它删除以前的文本lalala并将该字段留空。下面是我的代码:Mysql更新查询不会保存从文本区域写入

----------------------------- File 1 ----------- ----------------------

<? 
    include("header.inc.php"); 

    $result5 = mysql_query("SELECT faq FROM `demo_a_faq`"); 
    $myrow5 = mysql_fetch_row($result5); 

    $faq = $myrow5[0]; 

    ?> 
    <? 
    include("../templates/admin-header.txt"); 
    ?> 
    <form method="post" action="faq2.php"> 
    <TABLE bgcolor="#FFFFFF" bordercolor="#000008" border="0" width="95%" align="center"> 
    <TR> 
    <TD width="50%"><center><font face="Verdana, Arial, Helvetica, sans-serif" size="2">      <b>Edit FAQ:</b><br><textarea name="faneu" type="text" cols="80" rows="25"><? echo "$faq";  ?></textarea></TD> 
    </TR> 
    </TABLE><br><br> 
<center><input type="submit" value="Update"></form></center> 
<? 
include("../templates/admin-footer.txt"); 
?> 

--------------------- --------文件2 ---------------------------------

<? 
include("header.inc.php"); 

$asl = "UPDATE `demo_a_faq` SET `faq` = '$faneu'"; 
$results = mysql_query($asl) or die(mysql_error()); 

?> 
<? 
include("../templates/admin-header.txt"); 
?> 
<center><br><br><br><b>Updated!</b></center> 
<? 
include("../templates/admin-footer.txt"); 
?> 

在header.inc.php我只是有数据库连接。

有人可以告诉我为什么它不保存我在文本区域写入数据库的内容,因为它使我疯狂。

在此先感谢

回答

1

试试这个:

<?php 
include("header.inc.php"); 

// Always escape variables used in SQL-queries to avoid SQL-injections. 
$faneu = mysql_real_escape_string($_POST['faneu']); 

$asl = "UPDATE `demo_a_faq` SET `faq` = '$faneu'"; 
$results = mysql_query($asl) or die(mysql_error()); 

?> 
<? 
include("../templates/admin-header.txt"); 
?> 
<center><br><br><br><b>Updated!</b></center> 
<? 
include("../templates/admin-footer.txt"); 
?> 
+0

嗨。这完美谢谢。你是明星 –

0

你不发表您的textarea的值设置为 “FILES 2” .BE小心。

+0

嗨。愿你告诉我为什么你说“要小心”,因为安全是我网站的首要任务,如果有什么我想念我会很感激你让我知道。 –