SIM900 HTTP. errors when running code but OK in manual AT from terminal

Hi. I am working on a project sending data to a MYSQL server via sim900. Entering: [u]http://xxxxxxxxx.com/web/insert.php?UNIT=2&DATE=20189&TIME=9801&TI=216&TO=2526[/u] in a browser will update the server successfully.

The SIM900 is supposed to post this to a webpage and the variables will be stored.

By entering a sequence of AT commands the server updates the way it is supposed to do,
however when I run the AT sequence in code I get into trouble. The SIM900 throws "error"
after some of the AT commands and the sequence is not successful.

One of the things I notice when running the code is that the AT+HTTPPARA with "URL" and "HTTP://..." command get trunkated and the next line does not get the lf cr.

Here is the Arduino Code that I can not get to work corect:

/*
SIM900 minimum board from ITEAD STUDIO V1.0 
Connected to Serial1 Arduino mega.

Entering AT commands via terminal give no errors and 
sequence work without problems. The SIM900 then connect 
to website and activate PHP script to update the dummy
variable to MYSQL dataserver for logging.

Running this code SHOULD be equivalent to manually entering 
the AT commands, but it produces "error" results from SIM900.

Errors and success printout from the terminal listed below theis code.
first is from manual entering and second is from this code.


The AT+HTTPPARA="URL","http://xxxxx--->    gets trunkated in the middle 
of the feedback print and the <cr><lf> is lost, hence the next AT-command
does not come on a new line.

*/

#define GPRS Serial1

void setup()
{
  pinMode(7,OUTPUT);digitalWrite(7,HIGH);
Serial.begin(9600);
GPRS.begin(9600);
Serial.println("Starting AT query in 15 seconds");
digitalWrite(7,LOW);   //toggle power pin low 
delay(500);            //wait 500ms
digitalWrite(7,HIGH);  //toggle power pin back high
delay(14500);           //delay for sim900 to start up
Serial.flush();  GPRS.flush();  //remove the rdy message.
sendAT();        //start the AT sequence

}

void loop()
{
Serial.println("Looping Empty");
ShowSerialData();
delay(15000);

}

void sendAT()
{
  GPRS.print("AT+CREG?\r\n");   
  delay(5000); 
  ShowSerialData();
   
  GPRS.print("AT+SAPBR\r\n");
  delay(5000); 
  ShowSerialData();
  
  GPRS.println("AT+SAPBR=1,1\r\n");
  delay(5000); 
  ShowSerialData();

  GPRS.println("AT+HTTPINIT\r\n");  
  delay(5000); 
  ShowSerialData();

  String mystring="AT+HTTPPARA=";mystring+='"';mystring+="URL";mystring+='"';
  mystring+=',';mystring+='"';mystring+="http:/";
  mystring+="/xxxxxxxxx.com/web/insert.php?UNIT=5402&DATE=201289&TIME=9801&TI=216&TO=2526";
  mystring+='"';mystring+='"';
 
  GPRS.print(mystring);
  GPRS.print("\r\n");
  delay(5000); 
   ShowSerialData();

  GPRS.println("AT+HTTPACTION=0");
  delay(5000); 
   ShowSerialData();

  GPRS.println("AT+HTTPREAD");//get local IP adress
  delay(5000); 
  ShowSerialData();

  GPRS.println("AT+HTTPTERM");
  delay(5000); 
  ShowSerialData();
}

void ShowSerialData()
{
  delay(50);
  while(!GPRS.available());
  if(GPRS.available()){
    while(GPRS.available()){
      Serial.write(GPRS.read());
    }
  }
}

Here is the Terminal printout from manually entering AT commandsequence with terminal:

AT+CREG?
+CREG: 0,1
OK
AT+SAPBR=2,1
+SAPBR: 1,3,"0.0.0.0"
OK
AT+SAPBR=1,1
OK
AT+HTTPINIT
OK
AT+HTTPPARA="URL","http://xxxxxxxxx.com/web/insert.php?UNIT=2&DATE=20189&TIME=9801&TI=216&TO=2526"
OK
AT+HTTPPARA="CID",1
OK
AT+HTTPACTION=0
OK
+HTTPACTION:0,200,201
AT+HTTPREAD
+HTTPREAD:201
Connected successfully
mysql_query(INSERT INTO `Data1`  (`UNIT_NAME`, `DATE`, `TIME`, `TEMP_IN`, `TEMP_OUT` ) VALUES ('x2','2012/8/9','9:8:01','21.6','25.26'))
New record created successfully

OK
AT+HTTPTERM
OK

Here is the terminal printout from running the Arduino code with errors:

Starting AT query in 15 seconds

AT+CREG?
+CREG: 0,1
OK
AT+SAPBR
ERROR
AT+SAPBR=1,1
ERROR
AT+HTTPINIT
OK
AT+HTTPPARA="URL","http://xxxxxxxxx.com/web/insert.php?UNIT=540AT+HTTPACTION=0
ERROR
AT+HTTPREAD
OK
AT+HTTPTERM
OK

Looping Empty

The SIM900 is supposed to post this to a webpage

That doesn't make sense. Either the device with the SIM900 attached is acting as a server, and serving up a web page, or the device is acting as a client and making GET requests to a server.

In neither case can you "post to a web page".

Serial.flush();  GPRS.flush();  //remove the rdy message.

Why are you putting multiple statements on one line?

Why, not having yet sent anything to the serial 1 port, are you waiting for the outgoing serial 1 buffer to be empty? Why does it matter that the outgoing serial buffer is empty?

  while(!GPRS.available());
  if(GPRS.available()){

Under what circumstances will the while loop end? Is there any reason to then test that there is something in the serial 1 buffer?

AT+SAPBR

Given that the SAPBR command appears to need arguments, why would you send the command with no arguments?

AT+SAPBR=2,1
+SAPBR: 1,3,"0.0.0.0"
OK
AT+SAPBR=1,1
OK

vs.

AT+SAPBR=1,1
ERROR

Why are you NOT sending the same set of commands?