I am a little new at web design so if someone could help with this it would be great.
I am creating a form where my boss can enter news that he would like to post to our site.
fields include
- id
- data
- title
- summary
- news article
The problem is we have two servers a web machine and a database. Only the web machine can write the the database so on submit I need to save the data that is entered on the form as a sql file on the web machine and then use a cron job to insert the data to the database machine.
My problem is I don't know how to save the data to the file. Could someone help?
My development environment is linux/apache/php/postgres
Thanks
Hi,
Well firstly get all the details on the webmachine into a local file as below while I assume that you know that part of fetching the data namely id, data, news, summary and so on into variables! Next, we shall write the data into a text file separated by " | " as a delimiter. I have used a file named webmachine.txt
$myFile = "webmachine.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = $id."|".$data."|".$title."|".$summary."|".$news_ar ticle.\n;
fwrite($fh, $stringData);
fclose($fh);
Please note the use of \n at the last, We use \n so that one row is one row of the table in your db.
Next, inorder to enter the data into your db from the file,
LOAD DATA LOCAL INFILE 'webmachine.txt'
INTO TABLE your_table_name_here
FIELDS TERMINATED BY '|'
LINES TERMINATED BY '\n';
Hope this helps you. Regards
CyberKing