phpbb forum inserting data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nomad
    Recognized Expert Contributor
    • Mar 2007
    • 664

    phpbb forum inserting data

    I have a forum and I'm using phpbb and I want to insert data from a text file into the table.
    My problem is I only have the first and last name, and their e-mail address, the password and user name will be the same for everyone.
    How do I go about doing this.
    There is an id which is done automatically.
    There are about 25 plus fields that are in the db.

    ie setting up the id number.
    do I add the id number to the text file.

    could I write a sql statement instead?

    I'm using phpMyAdmin

    thanks
    nomad
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    I do not quite understand the problem. Inserting text data into a table is rather straight forward, depending on the data type of the db field: that must be able to contain the max. length of the text. So PHP code for this would be e.g.[php]$file = 'your_textfile' ;
    $fh = fopen($file, 'r');
    $text = fread($fh, filesize($file) );
    fclose($fh);
    $sql="INSERT INTO table_name (text_field) VALUES('$text') ";
    $result=mysql_q uery($sql)
    or die("Error inserting : ".mysql_error() );
    ... etc ...
    [/php]Since you gave no more information on the nhow mand what, I'll wait until you provide that.

    Ronald

    Comment

    • nomad
      Recognized Expert Contributor
      • Mar 2007
      • 664

      #3
      Originally posted by ronverdonk
      I do not quite understand the problem. Inserting text data into a table is rather straight forward, depending on the data type of the db field: that must be able to contain the max. length of the text. So PHP code for this would be e.g.[php]$file = 'your_textfile' ;
      $fh = fopen($file, 'r');
      $text = fread($fh, filesize($file) );
      fclose($fh);
      $sql="INSERT INTO table_name (text_field) VALUES('$text') ";
      $result=mysql_q uery($sql)
      or die("Error inserting : ".mysql_error() );
      ... etc ...
      [/php]Since you gave no more information on the nhow mand what, I'll wait until you provide that.

      Ronald
      Hi Ronald:
      thanks for the reply. In a phpbb forum they have about 35 plus fields a client can fill out. This is for a Cycling Club/Team that I'm on so we want to add the team members to the forum. They only info we have is the first, last name, and email... I need to add a password and user name, plus the date.
      They do have a primary key which is used for the id number which is made randomly.
      I was wondering what would be the best way in adding the data to the db, they're are about 76 team members.

      thanks
      nomad

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        What is the format of a record in the textfile? Is it CSV, fixed length fields, ??

        Ronald

        Comment

        • nomad
          Recognized Expert Contributor
          • Mar 2007
          • 664

          #5
          Originally posted by ronverdonk
          What is the format of a record in the textfile? Is it CSV, fixed length fields, ??

          Ronald
          Thanks for replying back Ronald:
          Right now its in excel, but i can make it into a csv.
          As for the fixed length fields for the table of user
          user_id mediumint(8) pk
          username varchar(25)
          user_email varchar(255)
          user_password varchar(32)
          user_regdate int(11)

          there are about 25 more fields, but those that I listed I have data on or I can make data on minus the user_id which is random maded.


          damon

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #6
            When it is a simple file you can export it from Excel in csv format and read it in using the php fgetcsv() command. The following sample reads and prints the entire contents of a CSV file (from php documentation)[php]<?php
            $row = 1;
            $handle = fopen("test.csv ", "r");
            while (($data = fgetcsv($handle , 1000, ",")) !== FALSE) {
            $num = count($data);
            echo "<p> $num fields in line $row: <br /></p>\n";
            $row++;
            for ($c=0; $c < $num; $c++) {
            echo $data[$c] . "<br />\n";
            }
            }
            fclose($handle) ;
            ?> [/php]and , from the same source, a way to map the heading/column names to the elements on each line.[php]$handle = fopen('somefile .csv', 'r');
            if ($handle) {
            set_time_limit( 0);
            //the top line is the field names
            $fields = fgetcsv($handle , 4096, ',');
            //loop through one row at a time
            while (($data = fgetcsv($handle , 4096, ',')) !== FALSE) {
            $data = array_combine($ fields, $data);
            }
            fclose($handle) ;
            } [/php]Ronald

            Comment

            • nomad
              Recognized Expert Contributor
              • Mar 2007
              • 664

              #7
              Originally posted by ronverdonk
              When it is a simple file you can export it from Excel in csv format and read it in using the php fgetcsv() command. The following sample reads and prints the entire contents of a CSV file (from php documentation)[php]<?php
              $row = 1;
              $handle = fopen("test.csv ", "r");
              while (($data = fgetcsv($handle , 1000, ",")) !== FALSE) {
              $num = count($data);
              echo "<p> $num fields in line $row: <br /></p>\n";
              $row++;
              for ($c=0; $c < $num; $c++) {
              echo $data[$c] . "<br />\n";
              }
              }
              fclose($handle) ;
              ?> [/php]and , from the same source, a way to map the heading/column names to the elements on each line.[php]$handle = fopen('somefile .csv', 'r');
              if ($handle) {
              set_time_limit( 0);
              //the top line is the field names
              $fields = fgetcsv($handle , 4096, ',');
              //loop through one row at a time
              while (($data = fgetcsv($handle , 4096, ',')) !== FALSE) {
              $data = array_combine($ fields, $data);
              }
              fclose($handle) ;
              } [/php]Ronald
              Thanks a bunch Ronald!!!!
              I will try this with a single data line

              damon

              Comment

              • ronverdonk
                Recognized Expert Specialist
                • Jul 2006
                • 4259

                #8
                Good luck with it. Hope to hear back what your solution was.

                Ronald

                Comment

                Working...