By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,461 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

Saving Form as query to a file.

P: 27
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
Jun 1 '07 #1
Share this Question
Share on Google+
3 Replies


pbmods
Expert 5K+
P: 5,821
Heya, bdbeames. Welcome to TSDN!

You can connect to your MySQL server from your webserver. Just use the server's IP address as the hostname when you mysql_connect.
Jun 1 '07 #2

cyberking
P: 84
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
Jun 1 '07 #3

P: 27
Thanks

A little more tweaking on my end, but I believe I got it to work:)
Jun 1 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.