First you need a table with input.
Copy Code code 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" >
<title></title>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<script src= "Submit.js" language= "JavaScript" ></script>
<body>
Insert Knowledge Point
<form name= "Insertform" >
<label for= "question" ></label> knowledge points
<input name= "question" type= "text"/>
<br/><br/>
<label for= "Answer" > Answer </label>
<input name= "Answer" type= "text"/>
<br/>
<br/>
<input name= "Confirm" value= Add "type=" button "onclick=" GetValue (); " >
</form>
</body>
JS is required to process the submitted data to the server and retrieve the returned data from the server. Submit.js code such as:
Copy Code code 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, which is responsible for exchanging data with the server
Copy Code code 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 = "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 ', ' no ')");
Mysql_close ($con);
echo "Input Success";
?>