Jump to content

Inserting a Row into a Table


lalabored

Recommended Posts

I have information in the form of name, details and date due in my database.  How can I retrieve the data from the database as ajax response text and insert it as a new row in a table with a column for name, details and date due?

Make a form with a input button that calls an AJAX function using onclick function. Then in the AJAX function, use the .open("GET", "php_file_name" + input_fields, true); and .send(null); to call a php file which would do that. You have to obviously pass the info from the forms into a PHP file's address so it can get the data. Then use php to do the rest.

 

I don't see why you didn't just go with straight forward PHP. ???

I have information in the form of name, details and date due in my database.  How can I retrieve the data from the database as ajax response text and insert it as a new row in a table with a column for name, details and date due?

Make a form with a input button that calls an AJAX function using onclick function. Then in the AJAX function, use the .open("GET", "php_file_name" + input_fields, true); and .send(null); to call a php file which would do that. You have to obviously pass the info from the forms into a PHP file's address so it can get the data. Then use php to do the rest.

 

I don't see why you didn't just go with straight forward PHP. ???

 

After PHP gets the data, how could I put the data in such a way in the responsetext so that I can use javascript to insert a new row into my table?  I am inserting data into a form, that form uses ajax to insert data into a database and then I need it to return the new data inserted in a formatted form and then insert it as a new row in the table that's already on the page without refreshing the page.

I still don't understand. Try something like:

 

HTML/JavaScript

<script>
function myAjaxFunction(){
// ajax object creation here //
meAjax.onreadystatechange=function(){
if (meAjax.readyState==4){
var blah = meAjax.responseText;
document.getElementById("bloh").innerHTML = blah;
}}}
</script>

<form name='whatever'>
<input type='text' id='name' /><br />
<input type='password' id='pwd' /><br />
<input type='button' name='submit' value='Get it!' onclick='myAjaxFunction()' />
</form>

<div id='bloh'></div>

 

PHP

<?php

// connect to database
// query name, details and date due
$return_string = "";
// put all html and text you want to return in $return_string
echo $return_string;
?>

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.