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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

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.