我插入MySQL中的textarea的內容和我獲取與PHP。 提交表格havnt問題,我可以插入新的數據。 我有不同的div和TextArea這就是爲什麼我不能使用輸入提交。 我使用Ajax,但比以前阿賈克斯負載process.php單擊這就是爲什麼獲得價值較早,插入舊數據。 我怎麼能在阿賈克斯加載process.php點擊或在無論如何textarea的與點擊進入新文本之後獲得的變量。 謝謝阿賈克斯負載PHP
<script type="text/javascript">
function useradd()
{
var data=$("#user,#user2,#user3,#user4").serialize();
$.ajax({
type: "POST",
url: "process.php",
data: data,
dataType: "html",
});
}
</script>
process.php
<?php
include'db.php';
$text1=$_POST['text1'];
$text2=$_POST['text2'];
$text3=$_POST['text3'];
$text4=$_POST['text4'];
$n=new db();
$n->connect();
$n->delete();
$n->insert($text1,$text2,$text3,$text4);
?>
插入
public function insert($text1,$text2,$text3,$text4)
{
$sql=mysql_query("REPLACE INTO strak(text1,text2,text3,text4) VALUES('$text1','$text2','$text3','$text4')");
if(!$sql)
{
echo mysql_error();
}
}
獲取代碼的textarea
<textarea id="t1" name="text1" style="height:100%;">
<?php
$conn=mysql_connect("localhost","fach","hektar12","p-d");
if($conn)
{ $seldb=mysql_select_db("p-d",$conn);
if($seldb)
{ $retrive=mysql_query("select text1 from strak",$conn);
if($retrive)
{ $result=mysql_fetch_row($retrive);
echo ($result[0]);
}
}
}
mysql_close($conn);
?>
</textarea>
你有多少種方法要問這個問題? – RiggsFolly 2014-10-07 10:15:40
爲什麼不能使用簡單的提交按鈕? – RiggsFolly 2014-10-07 10:16:08
是什麼導致你的javascript'useradd()'函數運行? – RiggsFolly 2014-10-07 10:17:01