Ajax PHP Implementation write database _php tutorial

Source: Internet
Author: User
First you need a table with input.
Copy CodeThe code is as follows:




<title></title>




Insert Knowledge points




JS is required to process the submission data to the server and the return data from the server for the commit. Submit.js code such as:
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, responsible for exchanging data with the server
Copy CodeThe code is as follows:
/*
* 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 ', ' none ')");
Mysql_close ($con);
echo "Input Success";
?>

http://www.bkjia.com/PHPjc/320528.html www.bkjia.com true http://www.bkjia.com/PHPjc/320528.html techarticle First, you need a table with input. The Copy code code is as follows:!--to change this template, choose Tools | Templates and open the template in the editor. -- ! DOCTYPE HTML Public "-// ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.