Loop GSM Connection to connect to web every 20 seconds

Hi, i want to ask how to loop GSM Connection connect to web every 20 seconds. I want to submit data into database every 20 seconds. Right now my code working but the code submit to database 1 time only. I already try put GSM code in separate function and call the function inside loop but not working. Below i attach my working code and not working code. I use Arduino Uno with Arduino GSM Shield and Adafruit Ultimate GPS Shield.

Here is the description for Adafruit GPS Shield:
Adafruit Library for reference - https://github.com/adafruit/Adafruit-GPS-Library
Adafruit GPS SHield Info - Overview | Adafruit Ultimate GPS Logger Shield | Adafruit Learning System

My Working Code (Submit only 1 time to database)

// ********************************************
//   GPS Library
// ********************************************
#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
#include <stdlib.h>


// ********************************************
//   GSM Library
// ********************************************
#include <GSM.h>


// ********************************************
//   Sim Card Pin Number if available
// ********************************************
#define PINNUMBER ""


// ********************************************
//   Set Up APN data for GPRS Connection
// ********************************************
#define GPRS_APN       "Maxis" // replace your GPRS APN
#define GPRS_LOGIN     "maxis"    // replace with your GPRS login
#define GPRS_PASSWORD  "wap" // replace with your GPRS password

// ********************************************
//   Initialize GSM Library
// ********************************************
GSMClient client;
GPRS gprs;
GSM gsmAccess; 

// ********************************************
//   Setup Arduino to browse URL/web through GPRS
//   The code below will setup path like:
//   http://arella.com.my/urltomysql.php?firstname=Muhammad&lastname=Faiz
//   When Arduino browse the web, it will submit firstname:Muhammad
//   and lastname:Faiz into database. I want to store GPS data into database later
// ********************************************
char server[] = "arella.com.my";
char path[] = "/urltomysql.php?user_id=2&latitude=745.56&longitude=234.5465&speed=4.83";
int port = 80; // port 80 is the default for HTTP


// ********************************************
//  Set Adafruit GPS to use software serial on pin 
//  D9 & D10 on Arduino. Use Jumper Wire from D7,D8 to D9,D10
// ********************************************
SoftwareSerial mySerial(10, 9);
Adafruit_GPS GPS(&mySerial);


// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
// Set to 'true' if you want to debug and listen to the raw GPS sentences. 
#define GPSECHO  false

// this keeps track of whether we're using the interrupt
// off by default!
boolean usingInterrupt = false;
void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy


//***********************************************
// convert NMEA GPS Format to Google Map Format
//***********************************************
int degLatInt, degLongInt;
float minLatFloat, minLongFloat, googleMapsLat, googleMapsLong;
char* lat_str = new char[10];
char* long_str = new char[10];
char degLatString[5], degLongString[5];

 boolean notConnected = true;


void setup()  
{ 
    Serial.begin(115200);
   while(notConnected)
  {
    if((gsmAccess.begin(PINNUMBER)==GSM_READY) &
      (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY))
      notConnected = false;
    else
    {
      Serial.println("Not connected");
      delay(1000);
    }
  }

  //***********************************************
  // Setup Adafruit GPS Shield
  //***********************************************
  // connect at 115200 so we can read the GPS fast enough and echo without dropping chars
  // also spit it out

  Serial.println("Adafruit GPS library basic test!");

  // 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800
  GPS.begin(9600);
  
  // uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  // uncomment this line to turn on only the "minimum recommended" data
  //GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
  // For parsing data, we don't suggest using anything but either RMC only or RMC+GGA since
  // the parser doesn't care about other sentences at this time
  
  // Set the update rate
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);   // 1 Hz update rate
  // For the parsing code to work nicely and have time to sort thru the data, and
  // print it out we don't suggest using anything higher than 1 Hz

  // Request updates on antenna status, comment out to keep quiet
  GPS.sendCommand(PGCMD_ANTENNA);

  // the nice thing about this code is you can have a timer0 interrupt go off
  // every 1 millisecond, and read data from the GPS for you. that makes the
  // loop code a heck of a lot easier!
  useInterrupt(true);
  
    delay(1000);
    
}


// Interrupt is called once a millisecond, looks for any new GPS data, and stores it
SIGNAL(TIMER0_COMPA_vect) {
  char c = GPS.read();
  // if you want to debug, this is a good time to do it!
#ifdef UDR0
  if (GPSECHO)
    if (c) UDR0 = c;  
    // writing direct to UDR0 is much much faster than Serial.print 
    // but only one character can be written at a time. 
#endif
}

void useInterrupt(boolean v) {
  if (v) {
    // Timer0 is already used for millis() - we'll just interrupt somewhere
    // in the middle and call the "Compare A" function above
    OCR0A = 0xAF;
    TIMSK0 |= _BV(OCIE0A);
    usingInterrupt = true;
  } else {
    // do not call the interrupt function COMPA anymore
    TIMSK0 &= ~_BV(OCIE0A);
    usingInterrupt = false;
  }
}

uint32_t timer = millis();
void loop()                     // run over and over again
{
 // if a sentence is received, we can check the checksum, parse it...
  if (GPS.newNMEAreceived()) {
    // a tricky thing here is if we print the NMEA sentence, or data
    // we end up not listening and catching other sentences! 
    // so be very wary if using OUTPUT_ALLDATA and trytng to print out data
    //Serial.println(GPS.lastNMEA());   // this also sets the newNMEAreceived() flag to false
  
    if (!GPS.parse(GPS.lastNMEA()))   // this also sets the newNMEAreceived() flag to false
      return;  // we can fail to parse a sentence in which case we should just wait for another
  }

  // if millis() or timer wraps around, we'll just reset it
  if (timer > millis())  timer = millis();
  // approximately every 2 seconds or so, print out the current stats
  if (millis() - timer > 10000) { 
    timer = millis(); // reset the timer        
  
   if (client.connect(server, port))
  {
    Serial.println("connected");
    // Make a HTTP request:
    client.print("GET ");
    client.print(path);
    client.println(" HTTP/1.1");
    client.print("Host: ");
    client.println(server);
    client.println("Connection: keep-alive");
    client.println();
  } 
    Serial.println("");
    Serial.print("\nTime: ");
    Serial.print(GPS.hour+8, DEC); Serial.print(':');
    Serial.print(GPS.minute, DEC); Serial.print(':');
    Serial.print(GPS.seconds, DEC); Serial.print('.');
    Serial.println(GPS.milliseconds);
    Serial.print("Date: ");
    Serial.print(GPS.day, DEC); Serial.print('/');
    Serial.print(GPS.month, DEC); Serial.print("/20");
    Serial.println(GPS.year, DEC);
    Serial.print("Fix: "); Serial.print((int)GPS.fix);
    Serial.print(" quality: "); Serial.println((int)GPS.fixquality); 
    if (GPS.fix) {      
      Serial.print("Speed (KM): "); Serial.println(GPS.speed * 1.85);
    }
  }
}

Not Working Code

// ********************************************
//   GPS Library
// ********************************************
#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
#include <stdlib.h>



// ********************************************
//   GSM Library
// ********************************************
#include <GSM.h>


// ********************************************
//   Sim Card Pin Number if available
// ********************************************
#define PIN ""


// ********************************************
//   Set Up APN data for GPRS Connection
// ********************************************
#define APN       "Maxis" // replace your GPRS APN
#define LOGIN     "maxis"    // replace with your GPRS login
#define PASSWORD  "wap" // replace with your GPRS password

// ********************************************
//   Initialize GSM Library
// ********************************************
GSMClient client;
GPRS gprs;
GSM gsmAccess; 

// ********************************************
//   Setup Arduino to browse URL/web through GPRS
//   The code below will setup path like:
//   http://arella.com.my/urltomysql.php?firstname=Muhammad&lastname=Faiz
//   When Arduino browse the web, it will submit firstname:Muhammad
//   and lastname:Faiz into database. I want to store GPS data into database later
// ********************************************
char server[] = "arella.com.my";
//char path[] = "/urltomysql.php?user_id=2&latitude=745.56&longitude=234.5465&speed=4.83";
int port = 80; // port 80 is the default for HTTP


// ********************************************
//  Set Adafruit GPS to use software serial on pin 
//  D9 & D10 on Arduino. Use Jumper Wire from D7,D8 to D9,D10
// ********************************************
SoftwareSerial mS(10, 9);
Adafruit_GPS GPS(&mS);

int degLatInt, degLongInt;
float minLatFlt, minLongFlt, gMapLat, gMapLong;
char* lat_str = new char[10];
char* long_str = new char[10];
char degLatStr[5], degLongStr[5], charVal[10];
String gLong;



// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
// Set to 'true' if you want to debug and listen to the raw GPS sentences. 
#define GPSECHO  false

// this keeps track of whether we're using the interrupt
// off by default!
boolean useI = false; //Using Interrupt
void uI(boolean); // Func prototype keeps Arduino 0023 happy


//***********************************************
// convert NMEA GPS Format to Google Map Format
//***********************************************



void setup()  
{ 
    Serial.begin(115200);

  //***********************************************
  // Setup Adafruit GPS Shield
  //***********************************************
  // connect at 115200 so we can read the GPS fast enough and echo without dropping chars
  // also spit it out

  Serial.println(F("Adafruit GPS library basic test!"));

  // 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800
  GPS.begin(9600);
  
  // uncomment this line to turn on only the "minimum recommended" data
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
  // For parsing data, we don't suggest using anything but either RMC only or RMC+GGA since
  // the parser doesn't care about other sentences at this time
  
  // Set the update rate
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);   // 1 Hz update rate
  // For the parsing code to work nicely and have time to sort thru the data, and
  // print it out we don't suggest using anything higher than 1 Hz

  // Request updates on antenna status, comment out to keep quiet
  GPS.sendCommand(PGCMD_ANTENNA);

  // the nice thing about this code is you can have a timer0 interrupt go off
  // every 1 millisecond, and read data from the GPS for you. that makes the
  // loop code a heck of a lot easier!
  uI(true);
  
    delay(1000);
    
  
    //***********************************************
  // Setup GSM
  //***********************************************
}


// Interrupt is called once a millisecond, looks for any new GPS data, and stores it
SIGNAL(TIMER0_COMPA_vect) {
  char c = GPS.read();
  // if you want to debug, this is a good time to do it!
#ifdef UDR0
  if (GPSECHO)
    if (c) UDR0 = c;  
    // writing direct to UDR0 is much much faster than Serial.print 
    // but only one character can be written at a time. 
#endif
}

void uI(boolean v) {
  if (v) {
    // Timer0 is already used for millis() - we'll just interrupt somewhere
    // in the middle and call the "Compare A" function above
    OCR0A = 0xAF;
    TIMSK0 |= _BV(OCIE0A);
    useI = true;
  } else {
    // do not call the interrupt function COMPA anymore
    TIMSK0 &= ~_BV(OCIE0A);
    useI = false;
  }
}

uint32_t timer = millis();
void loop()                     // run over and over again
{
 // if a sentence is received, we can check the checksum, parse it...
  if (GPS.newNMEAreceived()) {
    // a tricky thing here is if we print the NMEA sentence, or data
    // we end up not listening and catching other sentences! 
    // so be very wary if using OUTPUT_ALLDATA and trytng to print out data
    //Serial.println(GPS.lastNMEA());   // this also sets the newNMEAreceived() flag to false
  
    if (!GPS.parse(GPS.lastNMEA()))   // this also sets the newNMEAreceived() flag to false
      return;  // we can fail to parse a sentence in which case we should just wait for another
  }

  // if millis() or timer wraps around, we'll just reset it
  if (timer > millis())  timer = millis();
  // approximately every 2 seconds or so, print out the current stats
  if (millis() - timer > 10000) { 
    timer = millis(); // reset the timer
    
    //Serial.print(F("\nTime: "));
    //Serial.print(GPS.hour, DEC); Serial.print(F(":"));
   // Serial.print(GPS.minute, DEC); Serial.print(F(":"));
    //Serial.print(GPS.seconds, DEC); Serial.print(F("."));
    //Serial.println(GPS.milliseconds);
    //Serial.print("Date: ");
   // Serial.print(GPS.day, DEC); Serial.print(F('/'));
    //Serial.print(GPS.month, DEC); Serial.print("/20");
   // Serial.println(GPS.year, DEC);
    Serial.print(F("Fix: ")); Serial.print((int)GPS.fix);
    //Serial.print(F(" quality: ")); Serial.println((int)GPS.fixquality); 
    if (GPS.fix) {      
     /////////// Latitude /////////////
      // Convert NMEA Latitude to String
      dtostrf(GPS.latitude, 7, 4, lat_str); //convert GPS.latitude from float to String. 7 - means 8 characters long ; 4 - means 4 decimal point 
            
      // Get Degree substring from latitude String
      strncpy(degLatStr, lat_str, 1); // Get Degree from Full Latitude String. Example 311.7799 - Get 3
      
      // Get Minutes substring from latitude String
      char* minLatStr = lat_str + 1; // Move pointer up 1 position. Example 311.7799 will move to 11.7799

      // Convert Deg String to int
      degLatInt = atoi(degLatStr);
      
      // COnvert Min String to float
      minLatFlt = atof(minLatStr);
      
      //Convert NMEA latitude to Google Maps latitude
      gMapLat = degLatInt + (minLatFlt / 60); 
      //Serial.print("Google Map Latitude: ");
      Serial.println(gMapLat,4);
      
      //////////// Longitude /////////////
      // Convert NMEA Longitude to String
      dtostrf(GPS.longitude, 8, 4, long_str); //convert GPS.latitude from float to String. 8 - means 9 characters long ; 4 - means 4 decimal point 
            
      // Get Degree substring from latitude String
      strncpy(degLongStr, long_str, 3); // Get Degree from Full Latitude String. Example 10141.91699 - Get 141
      
      // Get Minutes substring from latitude String
      char* minLongStr = long_str + 3; // Move pointer up 3 position. Example 10141.9169 will move to 41.7799
      
      // Convert Deg String to int
      degLongInt = atoi(degLongStr);
      
      // COnvert Min String to float
      minLongFlt = atof(minLongStr);
      

      //Convert NMEA latitude to Google Maps latitude
      gMapLong = degLongInt + (minLongFlt / 60); 
      //Serial.print(F("Google Map Longitude: "));
      gLong = dtostrf(gMapLong,4,4,charVal);
      Serial.println(gMapLong,4);
      
      Serial.print(F("Speed (KM): ")); Serial.println(GPS.speed * 1.85);
      Serial.println(gLong);
      sendToDB(gLong);
    }
  }
}

void sendToDB(String gLong)
{
    //Not Connected Boolean
     boolean nc = true;
     while(nc)
  {
    if((gsmAccess.begin(PIN)==GSM_READY) &
      (gprs.attachGPRS(APN, LOGIN, PASSWORD)==GPRS_READY))
      nc = false;
    else
    {
      Serial.println(F("Not connected"));
      delay(1000);      
    }
  }
  
              if (client.connect(server, port))
  {
    String path = "/urltomysql.php?user_id=2&latitude=" + gLong + "&longitude=234.5465&speed=4.83";
    Serial.println(path);
    Serial.println(F("connected"));
    // Make a HTTP request:
    client.print(F("GET "));
    client.print(path);
    client.println(F(" HTTP/1.1"));
    client.print(F("Host: "));
    client.println(server);
    client.println(F("Connection: close"));
    client.println();
  } 
}