473,396 Members | 1,898 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Saving Form as query to a file.

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
3 1126
pbmods
5,821 Expert 4TB
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
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
Thanks

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

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

Similar topics

3
by: Martin Herrman | last post by:
Dear programmers, I have a form: <form action=".." method="post"> <textarea name="text1"></textarea> </form> And a php file that saves this variable to a file:
6
by: S. Graefner | last post by:
Hello Folks, I'm a Relitive newbie to the blood sport of MS ACCESS. I have designed and built a database with multiple, Related, tables. The db works well, more by good luck then good planing I...
2
by: Tolu | last post by:
Hello I am trying to save information from one form to two tables. I have a table for Student info and Transcript line. I have a form that list all the classes (using text boxes) a student is...
7
by: MacDermott | last post by:
For a client who wants answers, but doesn't want to bother to learn Access, I've built a cut-down query generator, where they can select fields and criteria. I then compose the appropriate SQL...
3
by: fstenoughsnoopy | last post by:
Ok the complete story. I have a Contact Table, Query and Form, that are used to input and store the contact info for customers. They have FirstName, LastName and Address as the primary key...
4
by: tt40 | last post by:
Anyone know how to prevent Access 2002 from automatically breaking all the incorrect joins in a query and then automatically saving the broken query? This is what I would call stupid design...
3
by: Nathan Guill | last post by:
I have an interface that works with an Access back-end. I would like to store and/or load user defined query strings per each user (i.e. no user can access another's queries). The idea I had was...
1
by: jcf378 | last post by:
Is it possible to set a main-form with an embedded subform to "Filter by Form", subsequently enter the desired variables in fields in BOTH the main-form and subform, and then save the resulting...
1
by: schweet1 | last post by:
Greetings, I am attempting to automate accessing and saving a file (a TIF) from the following URL: http://patimg1.uspto.gov/.DImg?Docid=US007376435&PageNum=1&IDKey=E21184B8FAD5 I have tried...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.