lalabored Posted January 4, 2008 Share Posted January 4, 2008 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? Link to comment https://forums.phpfreaks.com/topic/84437-inserting-a-row-into-a-table/ Share on other sites More sharing options...
Ken2k7 Posted January 4, 2008 Share Posted January 4, 2008 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 https://forums.phpfreaks.com/topic/84437-inserting-a-row-into-a-table/#findComment-430108 Share on other sites More sharing options...
lalabored Posted January 4, 2008 Author Share Posted January 4, 2008 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 https://forums.phpfreaks.com/topic/84437-inserting-a-row-into-a-table/#findComment-430698 Share on other sites More sharing options...
Ken2k7 Posted January 6, 2008 Share Posted January 6, 2008 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 https://forums.phpfreaks.com/topic/84437-inserting-a-row-into-a-table/#findComment-432144 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.