最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

ajax php 實(shí)現(xiàn)寫入數(shù)據(jù)庫

 更新時(shí)間:2009年09月02日 01:33:47   作者:  
看到同學(xué)背詞用的生詞本,覺得很不錯(cuò).正好自己也在看書,為了有一個(gè)好的效果,于是想做一個(gè)類似生詞本的,可以存知識(shí)點(diǎn),和查看知識(shí)點(diǎn)的.
首先需要一個(gè)帶輸入表格.
復(fù)制代碼 代碼如下:

<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="submit.js" language="javascript"></script>
</head>
<body>
Insert 知識(shí)點(diǎn)
<form name="insertForm">
<label for="question"></label>知識(shí)點(diǎn)
<input name="question" type="text"/>
<br/><br/>
<label for="answer"> 答案</label>
<input name="answer" type="text"/>
<br/>
<br/>
<input name="confirm" value="添加" type="button" onclick="getValue();">
</form>
</body>
</html>

需要js來處理提交數(shù)據(jù)到服務(wù)器上以及從服務(wù)器獲取提交后的返回?cái)?shù)據(jù). submit.js代碼如:
復(fù)制代碼 代碼如下:

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
var xmlHttp;
function getValue(){
alert("getvaluel");
var question =document.insertForm.question.value;
// alert(question);
var answer = document.insertForm.answer.value;
// alert(answer);
submit(question,answer);
};
function submit(question,answer){
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
xmlHttp.onreadystatechange =function(){
if(xmlHttp.readyState ==4){
alert(xmlHttp.responseText);
}
};
var url = "insert1.php";
xmlHttp.open("post",url,true);
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=utf-8");
xmlHttp.send("question="+question+"&answer="+answer);

}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}

然后PHP處理界面,負(fù)責(zé)跟服務(wù)器交換數(shù)據(jù)
復(fù)制代碼 代碼如下:

<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
//echo $_POST["question"];
//echo $_POST["answer"];
$q =$_POST['question'];
$a = $_POST['answer'];
//$q='qq';
//$a="a";
$con = mysql_connect("localhost","joe","123");
if (!$con)
{
//die('Could not connect: ' . mysql_error());
echo 'Could not connect: ' . mysql_error();
}
mysql_select_db("joe",$con);
mysql_query("INSERT INTO message VALUES ('$q', '$a', '無')");
mysql_close($con);
echo "輸入成功";
?>

相關(guān)文章

最新評(píng)論

霍州市| 宜川县| 连南| 红安县| 松阳县| 昌江| 吴忠市| 呼伦贝尔市| 曲水县| 和硕县| 云南省| 郴州市| 梅河口市| 江源县| 卓尼县| 化州市| 华亭县| 双桥区| 金溪县| 安平县| 临武县| 屏山县| 甘南县| 巴青县| 墨脱县| 黑河市| 固阳县| 额尔古纳市| 仪陇县| 湄潭县| 恩施市| 泉州市| 吉林省| 谢通门县| 北票市| 西和县| 上林县| 揭东县| 屏南县| 东乌| 融水|