<?
/* Author: Jeff Hines 1/14/01 (
[email protected])
** Resuable class for loading data into a single MySQL table.
** Constructor parameters LoadData(<tablename>, <databasename>).
** Function parameters InputMember(<Array- table fields>, <Array- fields input>).
 */
require("uservariables.php3");
class LoadData
{
     var $tableName;
     var $databaseName;
  
     /* Begin LoadData Constructor */
     function LoadData( $tblname, $dbname ){
        $this->tableName = $tblname;
        $this->databaseName = $dbname;
     }
     /* End LoadData Constructor */
    
     /* Begin InputMember function */
     function InputMember( $input1, $input2 ){ 
      
      /* Format the first field because of commas */
        $fields = $input1[ 0 ];
        $fieldValues = "'" . $input2[ 0 ] . "'";
      /* End formatting */
      
      /* Format field strings for submission */
      for ($idx = 1; $idx < count($input1); ++$idx) 
      $fields = $fields . ", " . $input1[ $idx ];
      for ($idx = 1; $idx < count($input2); ++$idx) 
      $fieldValues = $fieldValues . ", " . "'" . $input2[ $idx ] . "'";
   
      /* End field String formatting */
 
      /* Connect to database */
       if (!($link = mysql_pconnect ($hostName, $userName, $password))){
           echo("Error connecting to $hostName<BR>");
               exit();
              }
      /* Insert information into database */
      if(!($submitnew = mysql_db_query( $this->databaseName, "INSERT INTO $this->tableName
       ( $fields ) VALUES ( $fieldValues )"))){     
                   
       echo("Error inserting data into $this->databaseName<br>\n");
       exit();
       }
}
/* End Input Member Function */
}
/* End LoadData Class */
?>