jeeves245 Posted August 2, 2009 Share Posted August 2, 2009 Hi guys, Hoping to get some ideas here... Each week I have some data which needs to be sent to a MySQL database. The data is in a simple HTML form. The layout of the form stays the same from week to week but the data changes. What would be the best way to go about sending it to the database each week using PHP? I'm by no means a PHP expert but i'm learning pretty quickly. Cheers. Quote Link to comment https://forums.phpfreaks.com/topic/168493-solved-sending-data-in-html-form-to-database-using-php/ Share on other sites More sharing options...
jeeves245 Posted August 2, 2009 Author Share Posted August 2, 2009 Sorry, need to correct the above. The data is in an HTML TABLE, not a FORM. Form handling is easy. Not sure how to work with tables though. Quote Link to comment https://forums.phpfreaks.com/topic/168493-solved-sending-data-in-html-form-to-database-using-php/#findComment-888830 Share on other sites More sharing options...
Dânêl Posted August 2, 2009 Share Posted August 2, 2009 I'm not sure about what do you want to do. Your intention is to read data from that table with PHP and sending it to a mysql db? How does table data change ? (e.g. after a form submit, script execution...) I don't think reading data from html is a good solution. Knowing how data changes could suggest a better way. Temporizing script execution is possible if you could use Cron job, otherwise you have to call the appropriate PHP script Quote Link to comment https://forums.phpfreaks.com/topic/168493-solved-sending-data-in-html-form-to-database-using-php/#findComment-888833 Share on other sites More sharing options...
jeeves245 Posted August 2, 2009 Author Share Posted August 2, 2009 I'm not sure about what do you want to do. Your intention is to read data from that table with PHP and sending it to a mysql db? How does table data change ? (e.g. after a form submit, script execution...) I don't think reading data from html is a good solution. Knowing how data changes could suggest a better way. Temporizing script execution is possible if you could use Cron job, otherwise you have to call the appropriate PHP script The data changes when I am sent a new HTML document each week from a client. So it's not dynamic. I just need a way to easily put the data into a database. I figured using PHP to process it would be easy enough. Could be wrong? Quote Link to comment https://forums.phpfreaks.com/topic/168493-solved-sending-data-in-html-form-to-database-using-php/#findComment-888838 Share on other sites More sharing options...
Dânêl Posted August 2, 2009 Share Posted August 2, 2009 With xml everything could be easier. Anyway, I think you should load the HTML page into PHP (using fopen and fread) and then you could use regular expressions to find data. I can't post some code now because I didn't' use regular expression so much....so I don't remember them very well. I need to make some tests before posting examples to make them fullly functionally Quote Link to comment https://forums.phpfreaks.com/topic/168493-solved-sending-data-in-html-form-to-database-using-php/#findComment-888853 Share on other sites More sharing options...
jeeves245 Posted August 2, 2009 Author Share Posted August 2, 2009 How would XML be easier? I could probably ask the client to send me the data as XML if it's going to be a lot easier to work with. Quote Link to comment https://forums.phpfreaks.com/topic/168493-solved-sending-data-in-html-form-to-database-using-php/#findComment-888858 Share on other sites More sharing options...
_DarkLink_ Posted August 2, 2009 Share Posted August 2, 2009 Hello there, well, just went some 'googling' and found a little piece of code that could be interesting. you could modify it so that it will fit your situation. This code for now, reads your page with the table in it and does some processing. After doing so, it writes the data in a text file with a comma as separator for each new line. This is for a simple table form only and is not recommended for sending documents of great value. <?php $remote_url = 'http://example.com/page.html'; $local_file = 'whatever.txt'; $ch = curl_init($remote_url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $str = curl_exec($ch); curl_close($ch); $table_start = strpos($str, '<table>'); $table_end = strpos($str, '</table>') + strlen('</table>'); $table_len = $table_end - $table_start; $table = substr($str, $table_start, $table_len); $data = str_replace('</td>', ',', $table); $data = str_replace(',</tr>', "\n", $data); $data = strip_tags($data); $fp = fopen($local_file, 'w'); fwrite($fp, $data); fclose($fp); ?> Hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/168493-solved-sending-data-in-html-form-to-database-using-php/#findComment-888864 Share on other sites More sharing options...
Dânêl Posted August 2, 2009 Share Posted August 2, 2009 I think this is what you need http://www.phpfreaks.com/tutorial/handling-xml-data The first example explain how using XML is much easier and faster Quote Link to comment https://forums.phpfreaks.com/topic/168493-solved-sending-data-in-html-form-to-database-using-php/#findComment-888865 Share on other sites More sharing options...
jeeves245 Posted August 2, 2009 Author Share Posted August 2, 2009 Thanks for the info. I'll have a read of that XML tutorial Quote Link to comment https://forums.phpfreaks.com/topic/168493-solved-sending-data-in-html-form-to-database-using-php/#findComment-889136 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.