Ajax ASP page Ajax PHP implementation write database

Source: Internet
Author: User
First you need a table with input.

Copy the Code code as follows:










Insert Knowledge points


Knowledge points




Answer





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 the Code code 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";
?>

The above describes the Ajax ASP. Ajax PHP implementation to write to the database, including the Ajax ASP content, I hope the PHP tutorial interested in a friend helpful.

  • Related Article

    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.