Page 1 of 1

Data Validation From uploaded file before "Insert"

Posted: Mon Jan 18, 2010 3:51 am
by ecxzqute
hi Guys and PHP Guru's out there,

i've been doing my php-mysql project and i came to the part in which i found out that my code doesn't have validation wherein it saves all data that a log file has and now im banging my head in my bedroom wall because i can't make it work. :banghead:

here's a part of my code:

Code: Select all

    if($done){
        if(move_uploaded_file($_FILES['logFile']['tmp_name'], $filepath.$filename) == true)
            $fileuploaded = 1;
 
                $fileopen = fopen($filepath.$filename, "r");
                $sql = "";
             
                        if($fileuploaded){
                   $fileopen = fopen($filepath.$filename, "r");
 
                   $sql = "INSERT INTO temployeeattendancelog
                    (`AccessNo`
                    , `AccessNoPerMall`
                    , `DateLog`
                    , `TimeLog`
                    , `IPAddress`
                    , `ID_LogFileFormat`
                    , `ID_AttendanceLogType`)
                    VALUES ";
            
            if($fileopen){
                while(!feof($fileopen)){    
                
                    $qCompare = "";
                    $qInfo = array();
                                                                    
                    $qQuery = "select AccessNo, AccessNoPerMall, DateLog, TimeLog 
                                                        from temployeeattendancelog";
                        
                    $qResults = $c->query($qQuery);
                    
                     $ctr = 0;
 
                     while($row = $c->get_data($qResults)){ 
                            
                                    $AccessNo[$ctr] = $row['AccessNo'];
                                    $AccessNoPerMall[$ctr] = $row['AccessNoPerMall'];
                                    $DateLog[$ctr] = $row['DateLog'];
                                    $TimeLog[$ctr] = $row['TimeLog'];
                                    
                                    $content = fgets($fileopen);
                                            
                                    $content = explode(",", $content);
                                    
                                    if(trim($content[0]) != "" || trim($content[0]) != 0){
                                        
                                                                
                                        if($AccessNoPerMall[$ctr] == '".trim($content[1])"'
                                            && $DateLog[$ctr] == str_to_date('".trim($content[2])."', '%m/%d/%Y')
                                            && $TimeLog[$ctr] == '".trim($content[3])."'){
                                                        
                                        }//end of if($qInfo)
                                        
                                        else{                   
                                            
                                            $sql.= "
                                                (
                                                '".$branchcode."-".(int)trim($content[1])."'
                                                , ".(int)trim($content[1])."
                                                , str_to_date('".trim($content[2])."', '%m/%d/%Y')
                                                , '".trim($content[3])."'
                                                , '".trim($content[0])."'
                                                , '$idLogFile'
                                                , case when '".trim($content[4])."' = 'I' then '1' else '2' end ),";
                                        
                                        }//end of else ($qInfo)
                                    
                                    }//end of if(trim)
                                    
                                $ctr++;                               
                        }//end ofwhile                      
                }//end of first/outer-most while
            }//end of if(fileopen)
What my code has to do is to read a log file and stores into the table the data from the file but it must validate first whether such data or record already exist in the database and if so then the data will be ignored and only those which are not are to be inserted..

Any ideas is greatly appreciated..
(i really need your help guys..)

::im sorry if my English is poor, please bear with me..