First, you need an input table.
Copy codeThe Code is as follows: <! --
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 knowledge point
<Form name = "insertForm">
<Label for = "question"> </label> knowledge point
<Input name = "question" type = "text"/>
<Br/>
<Label for = "answer"> answer </label>
<Input name = "answer" type = "text"/>
<Br/>
<Br/>
<Input name = "confirm" value = "add" type = "button" onclick = "getValue ();">
</Form>
</Body>
</Html>
Js is required to process the submitted data to the server and obtain the submitted returned data from the server. The submit. js code is as follows:Copy codeThe Code is as follows :/*
* 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;
}
Then the PHP processing interface is responsible for exchanging data with the server.Copy codeThe Code is as follows: <? 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 = "";
$ 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', 'None ')");
Mysql_close ($ con );
Echo "input successful ";
?>