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)?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.