www.webdeveloper.com
Results 1 to 13 of 13

Thread: Notice: Undefined offset: 26

  1. #1
    Join Date
    Nov 2009
    Posts
    6

    Unhappy Notice: Undefined offset: 26

    For the life of me I can't figure out why I'm getting this error. Can anyone shed some light on to this?

    PHP Code:
    public function processBroadbandService($handle) {
         
    $goodMsg = array();
         
    $badMsg = array();

         
    $cnt 0;
         
    $goodCnt 0;
         
    $badCnt 0;
         
    $RECORD_LENGTH 26// should be a constant
         // Comments ignored

         
    while(($data fgetcsv($handle1000'|')) !== FALSE) {

           
    $cnt++;

           
    // Check for an invalid record length
           
    if(count($data) != $RECORD_LENGTH) {
              if(
    count($data) < $RECORD_LENGTH) {
                
    $badMsg[] = 'Record '.$cnt.' contains too few fields.';
              }
              if(
    count($data) > $RECORD_LENGTH) {
                
    $badMsg[] = 'Record '.$cnt.' contains too many fields.';
              }
              
    $badCnt++;
              continue;
           }

           
    // Record length is ok at this point so validate each field we care about
           
    if(!empty($data[0]) && !is_numeric($data[0])) {
             
    $badMsg[] = 'Record '.$cnt.' , supplier_id must be a number';
             
    $badCnt++;
             continue;
           }

        
    //  if(!strlen($data[2])) {
        //     $badMsg[] = 'Record '.$cnt.' , service name (i.e. Broadband) must be entered';
        //     $badCnt++;
          //   continue;
           //}

        //  if(!strlen($data[4])) {
        //     $badMsg[] = 'Record '.$cnt.' , service type (i.e. Residential, Business) must be entered';
         //    $badCnt++;
         //    continue;
         //  }


           // Ensure that our float and binary fields have values
           
    $binary = array(92019 );
           
    $float = array(101112131415161718 );

           foreach(
    $binary as $b) {
             if(isset(
    $data[$b])) {
               if(
    $data[$b] != 1) {
                 
    $data[$b] = 0;
               }
             } else {
               
    $data[$b] = 0;
             }
           }

           foreach(
    $float as $f) {
             if(isset(
    $data[$f])) {
               
    $data[$f] = number_format($data[$f],2);
             } else {
               
    $data[$f] = 0.00;
             }
           }


           if(!empty(
    $data[0])) { // update

             // verify that this row exists
             
    $confirmSQL "SELECT supplier_id from broadband_service WHERE supplier_id=".$data[0];
             if(
    $result $this->db->query($confirmSQL)) {
                if(
    $result->num_rows == 1) {

                  
    $updateCnt 1;
                  
    $updateSQL "UPDATE broadband_service SET 
                    id='"
    .$this->db->real_escape_string($data[$updateCnt++])."', 
                    supplier_id='"
    .$this->db->real_escape_string($data[$updateCnt++])."',
                    service_name='"
    .$this->db->real_escape_string($data[$updateCnt++])."', 
                    connection_type='"
    .$this->db->real_escape_string($data[$updateCnt++])."', 
                    service_type='"
    .$this->db->real_escape_string($data[$updateCnt++])."', 
                    download_speed='"
    .$this->db->real_escape_string($data[$updateCnt++])."',
                    spam_protection='"
    .$this->db->real_escape_string($data[$updateCnt++])."',
                    spyware_protection='"
    .$this->db->real_escape_string($data[$updateCnt++])."', 
                    webmail='"
    .$this->db->real_escape_string($data[$updateCnt++])."',
                    modem_deposit='"
    .$this->db->real_escape_string($data[$updateCnt++])."',
                    modem_rental='"
    .$this->db->real_escape_string($data[$updateCnt++])."',
                    modem_resale='"
    .$this->db->real_escape_string($data[$updateCnt++])."', 
                    modem_self_supplied='"
    .$this->db->real_escape_string($data[$updateCnt++])."',
                    virus_protection='"
    .$this->db->real_escape_string($data[$updateCnt++])."', 
                    firewall_service='"
    .$this->db->real_escape_string($data[$updateCnt++])."',
                    personal_webpage='"
    .$this->db->real_escape_string($data[$updateCnt++])."', 
                    router_support='"
    .$this->db->real_escape_string($data[$updateCnt++])."',
                    email_addresses='"
    .$this->db->real_escape_string($data[$updateCnt++])."',
                    email_space='"
    .$this->db->real_escape_string($data[$updateCnt++])."',
                    monthly_fee='"
    .$this->db->real_escape_string($data[$updateCnt++])."',
                    activation_fee='"
    .$this->db->real_escape_string($data[$updateCnt++])."',
                    payment_methods='"
    .$this->db->real_escape_string($data[$updateCnt++])."', 
                    supported_os='"
    .$this->db->real_escape_string($data[$updateCnt++])."',
                    static_ip='"
    .$this->db->real_escape_string($data[$updateCnt++])."',
                    dialup_hours='"
    .$this->db->real_escape_string($data[$updateCnt++])."',
                    tech_support='"
    .$this->db->real_escape_string($data[$updateCnt++])."'
                    
                    WHERE supplier_id="
    .$data[0];
                      
    //echo $updateSQL.'<hr >';

                  
    if($result $this->db->query($updateSQL)) {
                    
    $goodCnt++;
                  } else {
                    echo 
    $updateSQL;
                    echo 
    $this->db->error;
                    echo 
    '<hr >';
                  }
                } else {
                  
    $badMsg[] = 'Record '.$cnt.' , id '.$data[0].' does not exist.';
                }
             }
           } else { 
    // insert
              
    $updateCnt 1;
              
    $insertSQL "INSERT into broadband_service ( 
                                    id, 
                    supplier_id,
                    service_name, 
                    connection_type, 
                    service_type, 
                    download_speed,
                    spam_protection,
                    spyware_protection, 
                    webmail,
                    modem_deposit,
                    modem_rental,
                    modem_resale, 
                        modem_self_supplied,
                    virus_protection, 
                        firewall_service,
                    personal_webpage, 
                    router_support,
                    email_addresses,
                    email_space,
                    monthly_fee,
                    activation_fee,
                    payment_methods, 
                    supported_os,
                    static_ip,
                    dialup_hours,
                    tech_support
                  ) VALUES (

                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
              "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++]."
          
                  )"
    ;

             if(
    $result $this->db->query($insertSQL)) {
                      
    $goodCnt++;
                  } else {
                      echo 
    $this->db->error;
                  }
           }
         }

         if(
    $goodCnt 0) {
           
    $goodMsg[] = $goodCnt.' of '.$cnt.' rows processed successfully.';
         }

         return(array(
    $goodMsg$badMsg));
       } 

  2. #2
    Join Date
    Mar 2007
    Location
    Orlando
    Posts
    670
    It looks like you have 26 fields. PHP arrays are 0 based. Try changing $RECORD_LENGTH to 25.

  3. #3
    Join Date
    Nov 2009
    Posts
    6
    Quote Originally Posted by jasonahoule View Post
    It looks like you have 26 fields. PHP arrays are 0 based. Try changing $RECORD_LENGTH to 25.
    When I change the record length to 25 there is an output error of:

    Record XX contains too many fields.

    XX being the record number of course. So its definately not that.

  4. #4
    Join Date
    Mar 2007
    Location
    Orlando
    Posts
    670
    $updateCnt = 1 should be 0, no? Yeah, I would say that is definitely what is causing your problem.

  5. #5
    Join Date
    Nov 2009
    Posts
    6
    Quote Originally Posted by jasonahoule View Post
    $updateCnt = 1 should be 0, no? Yeah, I would say that is definitely what is causing your problem.
    I changed this and I am still presented with the error:

    Notice: Undefined offset: 26 in /var/www/SITENAME/htdocs/classes/admin_classes/SCRIPT.php on line 3087
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Mbps, No, Free, , 0,' at line 34
    Its not just this line either. Its every line that is being imported into the DB.
    Last edited by cenibyte; 11-04-2009 at 01:51 PM. Reason: Information addition

  6. #6
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,178
    Could you just do an implode of that array?
    PHP Code:
    $insertSQL "blah blah blah VALUES(" implode(','$data) . ")"
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  7. #7
    Join Date
    Dec 2005
    Posts
    2,984
    I agree with jasonahoule....did you change BOTH lines where $updateCnt = 1?

    Judging by the fact that you are 'still' presented with an undefined offset of 26, I say you didn't because the offset would only go as high as 25 if you changed it in both places.

    EDIT: That probably wouldn't work as it appears your first line is a supplierid.......did you write this script? Can you access any csv file that this application is supposed to be processing so we can have a look at it?
    Last edited by aj_nsc; 11-04-2009 at 02:33 PM.
    I've switched careers...
    I'm NO LONGER a scientist,
    but now a web developer...
    awesome.

  8. #8
    Join Date
    Nov 2009
    Posts
    6
    Quote Originally Posted by aj_nsc View Post
    I agree with jasonahoule....did you change BOTH lines where $updateCnt = 1?

    Judging by the fact that you are 'still' presented with an undefined offset of 26, I say you didn't because the offset would only go as high as 25 if you changed it in both places.

    EDIT: That probably wouldn't work as it appears your first line is a supplierid.......did you write this script? Can you access any csv file that this application is supposed to be processing so we can have a look at it?
    I changed both update lines to '0' and I'm presented with this now for every line being updated in the DB:

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' XXX, XXXXXXX , XXX, ' at line XX
    That probably wouldn't work as it appears your first line is a supplierid.......did you write this script? Can you access any csv file that this application is supposed to be processing so we can have a look at it?
    Yes I did write this script and here is a .csv import example of the data being processed:

    Code:
    product_id	Sr_no	product_name	connection_type	service_type	download_speed	spam_protection	spyware_protection	webmail	modem_deposit	modem_rental	modem_resale	modem_self_supplied	virus_protection	firewall_service	personal_webpage	wireless_router	email_addresses	email_space	monthly_fee	activation_fee	payment_methods	supported_os	static_ip	dialup_hours	tech_support
    	196	Extreme 	DSL	Residential	10 Mbps	No	Free						Free	Free	No	No	9		59.99	14.95
    Last edited by cenibyte; 11-04-2009 at 02:39 PM.

  9. #9
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,178
    The values need to be quoted within the SQL string (if they are not numeric).
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  10. #10
    Join Date
    Nov 2009
    Posts
    6
    Quote Originally Posted by NogDog View Post
    The values need to be quoted within the SQL string (if they are not numeric).
    Didn't work. Output below:

    Error 1:
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''service_name', 'connection_type', 'service_type', 'download_s' at line 4
    Code w/ Error 1
    PHP Code:
    $updateCnt 0;
              
    $insertSQL "INSERT into broadband_service ( 
                              id, 
                    supplier_id,
                    'service_name', 
                    'connection_type', 
                    'service_type', 
                    'download_speed',
                    'spam_protection',
                    'spyware_protection', 
                    webmail,
                    modem_deposit,
                    modem_rental,
                    modem_resale, 
                        modem_self_supplied,
                    'virus_protection', 
                        'firewall_service',
                    'personal_webpage', 
                    router_support,
                    'email_addresses',
                    email_space,
                    monthly_fee,
                    activation_fee,
                    payment_methods, 
                    supported_os,
                    static_ip,
                    dialup_hours,
                    tech_support
                    
                  ) VALUES (

                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  '"
    .$data[$updateCnt++]."',
                  '"
    .$data[$updateCnt++]."',
                  '"
    .$data[$updateCnt++]."',
                  '"
    .$data[$updateCnt++]."',
                  '"
    .$data[$updateCnt++]."',
                  '"
    .$data[$updateCnt++]."',
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
              "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  '"
    .$data[$updateCnt++]."',
                  '"
    .$data[$updateCnt++]."',
                 '"
    .$data[$updateCnt++]."',
                  "
    .$data[$updateCnt++].",
                  '"
    .$data[$updateCnt++]."',
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
              "
    .$data[$updateCnt++]."
          
                  )"

    Error 2:
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''service_name', 'connection_type', 'service_type', 'download_s' at line 4
    Code w/ Error 2
    PHP Code:
    $updateCnt 0;
              
    $insertSQL "INSERT into broadband_service ( 
                              id, 
                    supplier_id,
                    service_name, 
                    connection_type, 
                    service_type, 
                    download_speed,
                    spam_protection,
                    spyware_protection, 
                    webmail,
                    modem_deposit,
                    modem_rental,
                    modem_resale, 
                        modem_self_supplied,
                    virus_protection, 
                        firewall_service,
                    personal_webpage, 
                    router_support,
                    email_addresses,
                    email_space,
                    monthly_fee,
                    activation_fee,
                    payment_methods, 
                    supported_os,
                    static_ip,
                    dialup_hours,
                    tech_support
                    
                  ) VALUES (

                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  '"
    .$data[$updateCnt++]."',
                  '"
    .$data[$updateCnt++]."',
                  '"
    .$data[$updateCnt++]."',
                  '"
    .$data[$updateCnt++]."',
                  '"
    .$data[$updateCnt++]."',
                  '"
    .$data[$updateCnt++]."',
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
              "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  '"
    .$data[$updateCnt++]."',
                  '"
    .$data[$updateCnt++]."',
                 '"
    .$data[$updateCnt++]."',
                  "
    .$data[$updateCnt++].",
                  '"
    .$data[$updateCnt++]."',
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
              "
    .$data[$updateCnt++]."
          
                  )"

    Error 3:
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''service_name', 'connection_type', 'service_type', 'download_s' at line 4
    Code w/ Error 3
    PHP Code:
    $updateCnt 0;
              
    $insertSQL "INSERT into broadband_service ( 
                      id, 
                    supplier_id,
                    'service_name', 
                    'connection_type', 
                    'service_type', 
                    'download_speed',
                    'spam_protection',
                    'spyware_protection', 
                    webmail,
                    modem_deposit,
                    modem_rental,
                    modem_resale, 
                        modem_self_supplied,
                    'virus_protection', 
                        'firewall_service',
                    'personal_webpage', 
                    router_support,
                    'email_addresses',
                    email_space,
                    monthly_fee,
                    activation_fee,
                    payment_methods, 
                    supported_os,
                    static_ip,
                    dialup_hours,
                    tech_support
                    
                  ) VALUES (

                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
              "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
                  "
    .$data[$updateCnt++].",
              "
    .$data[$updateCnt++]."
          
                  )"


  11. #11
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,178
    All I can suggest at this point is to output the query string along with the error message so that you can see exactly what was sent to the DB. (You can even copy-and-paste it then if you want to try it from phpMyAdmin or the MySQL command line.)
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  12. #12
    Join Date
    Nov 2009
    Posts
    6
    So there is nothing jumping out other then the above laid out messages to anyone?

  13. #13
    Join Date
    Oct 2008
    Posts
    150
    The error message for number 2 doesn't match the sql from your script. The message shows the fields with single quotes around them, even though the script doesn't add them. Did you forget to save the script before you ran it?

    Don't use quotes, single or double, around field names.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles