SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JS validation for csv file

    hello friends

    i am php programmer.

    i want to explain you first what i am doing
    1) i have an excel sheet with named "Book1.csv".
    2)i am just dumping data from this file to database
    3) but now i want to check validation for it
    e.g. if one col is empty then ask like "in your file one column is empty,are you sure you want to insert file?" like this

    here i am showing you how i m importing my file in to database

    PHP Code:
    if(isset($_POST['Submit'])=="Upload")
      {
        
    $handle fopen ("C:\***\***\****\****\***\import\file-upload\files\Book1.csv","r");
           
        while (
    $data fgetcsv ($handle1000",")) {
                    
                    
    $prod_id =  $data[0];
                    
    $no_of_qt $data[1];
                    
    $notes =    $data[2];
                    
    $b_id =     $data[3];
                    
                
            
    //   $query = "LOAD DATA INFILE 'D:\ApacheGroup\Apache\htdocs\deepali\Book2.csv' INTO TABLE p_b FIELDS TERMINATED BY ',' ENCLOSED BY '"' ESCAPED BY '\\' LINES TERMINATED BY '\r\n'";
         
        
    $link=mysql_connect("""""") or die(mysql_error());
                     
    // echo 'Connected successfully';
                        //mysql_select_db("") or die(mysql_error());
                 
    $check mysql_query("SELECT prod_id FROM p_b WHERE prod_id='".$prod_id."'") or die(mysql_error());
                
                   if(
    mysql_num_rows($check) >= 1)
                             { 
    // if the prod already exists.
                             
    $link1=mysql_connect("""""") or die(mysql_error());
                                              
    // echo 'Connected successfully';
                        
    mysql_select_db("") or die(mysql_error());
                             
                             
    $query "UPDATE  p_b set  no_of_qt='".$no_of_qt."',notes='".$notes."' where prod_id='".$prod_id."'"
                                           
                    
    $result mysql_query($query) or die('Query failed: ' mysql_error());
                                          
                    
    // Printing results in HTML
                    
    if(mysql_affected_rows() > 0){
                                          
                                           echo 
    "Updation is done"mysql_affected_rows();
                                          
                                             }else{
                                          
                                           echo 
    "not done";
                                           
                                          }
                           echo 
    "The prod $prod_id already exists!";
                             }  
                     
                 
                        
                      else{
                      
    $link1=mysql_connect("""""") or die(mysql_error());
                                       
    // echo 'Connected successfully';
                        
    mysql_select_db("") or die(mysql_error());
           
    $query1 "INSERT INTO p_b (prod_id,no_of_qt,notes,b_id) values ('".$prod_id."','".$no_of_qt."','".$notes."','".$b_id."')";
           
    $result1 mysql_query($query1) or die('Query failed: ' mysql_error());
          if(
    mysql_affected_rows() > 0){
           
           echo 
    "inserted"mysql_affected_rows();
           
           
                }else{
           
                  echo 
    "not inserted"mysql_affected_rows();
           
             }
           }
         }
          
    fclose ($handle); 
          
        } else{
        echo 
    "please upload your file.";
        }
          
        
         
        
    //echo "product is inseted";
        //mysql_close($link);
        
        //mysql_free_result($check); 
    //    mysql_free_result($result) ;
        
        
    ?> 
    i am just confused here? because i am dumping all the data at onetime.
    please give me some suggestion,how could i do this?
    thanks in advance.

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Exactly what do you want to validate? The content of the file?

  3. #3
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes i want to validate content of the file.
    please give me some hint.

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    Javascript can't read files, so you would need to pass the full contents of the file to it.

    You should use PHP to validate the csv file instead of javascript.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes, even i was thinking that way only.
    but thank you.

  6. #6
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could read it (and write to it) in Internet Explorer only using the FileSystemObject (ActiveX object). But that is nothing that I would recommend...

  7. #7
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    means you mean to say that, i can do the validation with java script?

  8. #8
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Using an ActiveX object that will only work in Internet Explorer. Use this only if you are building an Intranet that is IE-only.

    ActiveX is one of the reasons that IE has so many security holes. Microsoft has therefore turned off ActiveX support by default in Internet Explorer 7.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •