if ($_post | | $_get)
{
$CN = MySQL tutorial _connect (' localhost ', ' root ', ' 123456a ');
$data = $_post[' data '];
$sql = "Update test set data= ' $data ' where id=1";
Mysql_db_query (' db ', $sql, $CN);
}
?>
<form name= "Form1" method= "Post" action= "" >
<label>
<input name= "DataValue" type= "text" id= "Data" >
</label>
<label>
<input type= "button" Name= "Submit" value= "Save Data" onclick= "JavaScript Tutorial: Ajaxsava ();" >
</label>
<div id= "DV111CN" ></div>
</form>
<script language= "JavaScript" >
var xmlhttp;
Function Ajaxsava () {
var url = "ajaxsava.php tutorial";
var Obao = Createhttpobject ();
var Data = Form1.datavalue.value;
alert (data);
obao.open ("POST", url,true);
obao.setrequestheader (' Content-type ', ' application/x-www-form-urlencoded ');
obao.onreadystatechange = function () {onreadystatechng ();};
obao.send ("Data=" +data);
}
function onreadystatechng () {
if (xmlhttp.readystate = = 4) {
if (Xmlhttp.status = = 200) {
Document.getElementById.innerHTML = unescape (Xmlhttp.responsetext);
}
else {
document.getElementById (' DV111CN '). InnerHTML = "failed, <a href= ' javascript:; ' onclick= ' checkrep (this); ' > re-submit </a> ";
}
}else{
document.getElementById (' DV111CN '). InnerHTML = "}
}
function Createhttpobject () {
try {
XMLHTTP = new ActiveXObject ("Msxml2.xmlhttp");
}
catch (e) {
try {
XMLHTTP = new ActiveXObject ("Microsoft.XMLHTTP");
}
catch (e) {
XMLHTTP = false;
}
}
if (!xmlhttp && typeof xmlhttprequest!= ' undefined ') {
try {
XMLHTTP = new XMLHttpRequest ();
}
catch (e) {
Xmlhttp=false;
}
}
if (!xmlhttp && window.createrequest) {
try {
XMLHTTP = Window.createrequest ();
}
catch (e) {
Xmlhttp=false;
}
}
return XMLHTTP;
}
</script>