Saving Form as query to a file.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bdbeames
    New Member
    • Jun 2007
    • 27

    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
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    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.

    Comment

    • cyberking
      New Member
      • Jan 2007
      • 84

      #3
      Originally posted by bdbeames
      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."|".$ne ws_article.\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

      Comment

      • bdbeames
        New Member
        • Jun 2007
        • 27

        #4
        Thanks

        A little more tweaking on my end, but I believe I got it to work:)

        Comment

        Working...