欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時間:2009年09月02日 01:33:47   作者:  
看到同學(xué)背詞用的生詞本,覺得很不錯.正好自己也在看書,為了有一個好的效果,于是想做一個類似生詞本的,可以存知識點(diǎn),和查看知識點(diǎn)的.
首先需要一個帶輸入表格.
復(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 知識點(diǎn)
<form name="insertForm">
<label for="question"></label>知識點(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)文章

  • php基于 swoole 實(shí)現(xiàn)的異步處理任務(wù)功能示例

    php基于 swoole 實(shí)現(xiàn)的異步處理任務(wù)功能示例

    這篇文章主要介紹了php基于 swoole 實(shí)現(xiàn)的異步處理任務(wù)功能,涉及swoole的安裝、配置及php調(diào)用swoole守護(hù)進(jìn)程監(jiān)控任務(wù)相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2019-08-08
  • php?日期時間處理函數(shù)小結(jié)

    php?日期時間處理函數(shù)小結(jié)

    php?日期時間處理函數(shù)小結(jié),包括日期轉(zhuǎn)換為星期、計(jì)算出兩個日期之間的月份等,值得參考下。
    2009-12-12
  • PHP+redis實(shí)現(xiàn)微博的拉模型案例詳解

    PHP+redis實(shí)現(xiàn)微博的拉模型案例詳解

    這篇文章主要介紹了PHP+redis實(shí)現(xiàn)微博的拉模型案例,結(jié)合具體實(shí)例形式詳細(xì)分析了php+redis獲取關(guān)注人最新信息的相關(guān)原理與操作技巧,需要的朋友可以參考下
    2019-07-07
  • PHP 輸出緩沖控制(Output Control)詳解

    PHP 輸出緩沖控制(Output Control)詳解

    本文主要介紹PHP 輸出緩沖控制,這里提供了詳細(xì)的相關(guān)資料及簡單示例代碼,幫助大家學(xué)習(xí)參考,有興趣的小伙伴可以參考下
    2016-08-08
  • 詳解PHP中mb_strpos的使用

    詳解PHP中mb_strpos的使用

    這篇文章主要介紹了詳解PHP中mb_strpos的使用,通過使用語法以及實(shí)例給大家詳細(xì)分析了用法,需要的朋友參考學(xué)習(xí)下。
    2018-02-02
  • php防止SQL注入詳解及防范

    php防止SQL注入詳解及防范

    SQL 注入是PHP應(yīng)用中最常見的漏洞之一。事實(shí)上令人驚奇的是,開發(fā)者要同時犯兩個錯誤才會引發(fā)一個SQL注入漏洞
    2013-11-11
  • PHP下利用shell后臺運(yùn)行PHP腳本,并獲取該腳本的Process ID的代碼

    PHP下利用shell后臺運(yùn)行PHP腳本,并獲取該腳本的Process ID的代碼

    PHP下利用shell后臺運(yùn)行PHP腳本,并獲取該腳本的Process ID的代碼,學(xué)習(xí)php的朋友可以參考下。
    2011-09-09
  • PHP中header()函數(shù)的七種用法小結(jié)

    PHP中header()函數(shù)的七種用法小結(jié)

    我們在實(shí)際開發(fā)中經(jīng)常使用header()實(shí)現(xiàn)一些功能,這篇文章介紹關(guān)于header()的7中用法,文中有詳細(xì)的代碼示例,具有一定的參考價值,需要的朋友可以參考下
    2023-08-08
  • PHP正則解析多重循環(huán)模板示例

    PHP正則解析多重循環(huán)模板示例

    這篇文章主要介紹了PHP正則解析多重循環(huán)模板,結(jié)合實(shí)例形式分析了php基于正則的循環(huán)遍歷與解析相關(guān)操作技巧,需要的朋友可以參考下
    2018-06-06
  • Ajax+PHP邊學(xué)邊練 之五 圖片處理

    Ajax+PHP邊學(xué)邊練 之五 圖片處理

    在上一篇中講解了如何通過Ajax提交表單并由PHP處理底層數(shù)據(jù),本篇將主要介紹圖片的上傳與處理。對于文件的上傳很簡單,只需一個Form便可實(shí)現(xiàn),再通過PHP將源文件上傳到目標(biāo)目錄。
    2009-12-12

最新評論