Jump to content

How to update the DataBase Table using the form loaded by Ajax


suri1980

Recommended Posts

Hi i need help on the following, check my code below.

 

access.html

 

<script language="javascript">

var XHRObj = false;

if (window.XMLHttpRequest)

{

XHRObj = new XMLHttpRequest();

}else if (window.ActiveXObject){

XHRObj = new ActiveXObject("Microsoft.XMLHTTP");

}

 

function getit(divid){

if (XHRObj)

{

var obj = document.getElementById(divid);

XHRObj.open("GET", "access.php?option=1");

XHRObj.onreadystatechange = function (){

if (XHRObj.readystate == 4 && XHRObj.status==200)

{

obj.innerHTML = XHRObj.responseText;

}

}

XHRObj.send(null);

}

}

</script>

<form name="sample">

<INPUT TYPE="button" name="but" value="Click Me!" onclick="getit('DisplayHere');">

</form>

<div id="DisplayHere">The Fetched data will be here</div>

 

access.php

 

<?

$conn = mysql_connect('localhost', 'root', '') or die(mysql_error());

$seldb = mysql_select_db('test');

?>

 

<FORM NAME="SAMPLE" METHOD="POST">

<INPUT TYPE="text" NAME="name">

<INPUT TYPE="button" value="Submit">

</form>

 

DB

 

sample - > {id(int),name(varchar)}

 

From the access.html on clicking the Click Me Button, i am loading another form using access.php at DisplayHere Div. In newly loaded form when i enter name and click submit button it should update the database. I tried all the possibilities to update the DB table but failed  :(.

 

Is it possible update at the same location (DisplayHere Div) with the message, Name submitted (it should be in access.html with ajax loaded form and with the updated message)?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.