我使用以下 javascript 将数据发送到数据库
var x=document.getElementById("sortable").innerHTML;
alert(x);
var http=new XMLHttpRequest();
http.open("POST", "5.php?field="+x, true);
http.onreadystatechange = function()
{
if(http.readyState == 4 && http.status == 200)
{
alert(http.responseText);
}
}
http.send();
在 php 端我使用以下函数:
$l=$_GET['field'];
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("formdem", $con);
$sql="INSERT INTO rohit(content)VALUES('$l')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "<br/>    Your Form is now ready to be filled.....";
$rs= mysql_query("Select * from rohit where content='$l'");
if(mysql_num_rows($rs)!=0)
{
while($row = mysql_fetch_array($rs)) {
echo "<br/>Your unique id is ".$row['formid'];
}
}
但是这段代码没有将完整的数据发送到数据库中。可能是什么原因。在数据库中,我将字段设为长文本。谢谢