BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 02-29-2012, 02:54 PM   #1
nesiar
New Member
 
Join Date: Feb 2012
Model: 9900
PIN: N/A
Carrier: mtn
Posts: 1
Default Issues with HTTP Post From Blackberry To Mysql ViaPHP

Please Login to Remove!

I am developing an application where i will need to collect user-unput and send to a PHP script on the server.I searched and got some code which showed me how to use a class for posting the data ...but the data does not get posted to the server.Where am i missing it?..Below is some of my code(N.B:I AM TESTING FROM A SIMULATOR USING MDS)..

Code:
  import net.rim.device.api.ui.*;
  import net.rim.device.api.ui.component.*;
  import net.rim.device.api.ui.container.*;
  import net.rim.device.api.system.*;

   /**
    * 
  */
  class IntroPage extends MainScreen{
// private members - these represent the "controls"
    private BasicEditField identifierfield = null;
    private BasicEditField datafield = null;
      private ButtonField submitbutton = null;
    private LabelField statusfield = null;
    IntroPage() { 
   super(); 
   setTitle("BB IBM Demo App");
   identifierfield = new BasicEditField("Identifier: ","",50, EditField.NO_NEWLINE );    
    // add this field to the screen
    add(identifierfield);

    // create a field for the data of our transaction
    datafield = new BasicEditField("Data: ","",100, EditField.NO_NEWLINE );    
    // add this field to the screen
    add(datafield);
    // createlistener
    FieldChangeListener listener = new FieldChangeListener() {
            public void fieldChanged(Field field, int context) {
                ButtonField submitbutton = (ButtonField) field;
               String id=identifierfield.getText();
               String data=datafield.getText();
               if(id.trim().length()==0||data.trim().length()==0)
               {
                Dialog.alert("Please Fill In All Fields.");
                return;  }
                if(bb_ibm_transaction.ProcessTransaction(id,data)==true)
                {
                   Dialog.alert("Your Data Has Been Saved Successfully");  }
                else
                {
                 Dialog.alert("There Was An Error Saving Your Details,Please Try Again Later.");    }
}
        }; 

    // create a button to submit our transaction
    submitbutton = new ButtonField("Submit Transaction",ButtonField.CONSUME_CLICK);
    submitbutton.setChangeListener(listener);


    // add this button to the screen
    add(submitbutton);

    // add a status label
    statusfield = new LabelField("Please enter transaction data.");
When i click on the submit button..i get the "There was an error saving your details" dialogue...(which means the connection class does not echo 'success'...thereby returns false) Below is the code for the Connection class:
Code:
    import net.rim.blackberry.api.browser.URLEncodedPostData;
   import java.io.InputStream;
   import java.io.InputStreamReader;
   import javax.microedition.io.HttpConnection;
   import javax.microedition.io.Connector;
    /**
    * 
   */
   class bb_ibm_transaction {
  bb_ibm_transaction() {    }
 // this method interacts with the server
 public static boolean ProcessTransaction(String id,String data)
{
    // default to non-success return code
    boolean ret = false;

    // some variables necessary for HTTP communication
    InputStream inputStream = null;
    HttpConnection httpConnection = null;


    // because many of the steps can throw an exception, wrap this method in           try/catch block
    try
    {

        StringBuffer returnStringBuffer = new StringBuffer();
        String returnString = new String();


        String desiredEncoding = "ISO-8859-1";


        URLEncodedPostData params = new URLEncodedPostData(URLEncodedPostData.DEFAULT_CHARSET, true);
        params.append("identifier", id);
        params.append("data", data);

        String url = "htxx://localhost/mob/test.php?" + params.toString();

        System.out.println(url);


        //Connecting to Server
        httpConnection = (HttpConnection)Connector.open(url);
        inputStream = httpConnection.openDataInputStream();

        if(httpConnection.getResponseCode() == HttpConnection.HTTP_OK)
        {
            int ch;

            //Process Response

            // check header field for a specific encoding
            String contenttype = httpConnection.getHeaderField("Content-Type");
            if (contenttype != null)
            {
                contenttype = contenttype.toUpperCase();
                if (contenttype.indexOf("UTF-8") != -1)
                {
                    desiredEncoding = "UTF-8";
                }
            }

            // get an inputstreamreader to handle utf-8 data
            InputStreamReader isr = new InputStreamReader(inputStream,desiredEncoding);

            while ((ch = isr.read()) != -1) 
            {
                returnStringBuffer.append((char) ch);
            }

            inputStream.close();
            httpConnection.close();
            inputStream = null;
            httpConnection = null;
            returnString = returnStringBuffer.toString();

            // examine return string
            if (returnString.indexOf("SUCCESS") != -1)
            {
                ret = true;
            }
            return ret;
        }
        inputStream.close();
        httpConnection.close();
        inputStream = null;
        httpConnection = null;
        //Bad Transaction.
        return ret;
    }
    catch (Exception e)
    {
        System.out.println("Error occurred in ProcessTransaction(" + id + "," + data + ")\n" + e.toString());
        return ret;
    }
    finally
    {
        try
        {
            if (inputStream != null)
                inputStream.close();
            if (httpConnection != null)
                httpConnection.close();
        }
        catch (Exception ee)
        {
        }
    }


}
  }
And this is the php script

Code:
   
<?php
   include 'mob_connect.php';
   $id=mysqli_real_escape_string($link,$_POST['id']);
 if($id)
{
echo "SUCCESS";
}
 ?>
Please Where Am I Missing It?
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads for: Issues with HTTP Post From Blackberry To Mysql ViaPHP
Thread Thread Starter Forum Replies Last Post
BES 5.0 Exchange/Domino final documentation posted illy BES Admin Corner 9 05-12-2009 11:16 AM
Blackberry Activation(s)... Barry_Black General BlackBerry Discussion 5 06-07-2007 12:07 PM
Blackberry Enterprise Activation Woes rgf207 BES Admin Corner 2 05-23-2007 02:21 PM
BES 4.0 SP3 for Exchange available for Download jnelson2000 BES Admin Corner 72 01-12-2006 02:44 PM


Lot of OEM APPLE iPAD LCD And White Front Glass Replacement 6091l-1402C picture

Lot of OEM APPLE iPAD LCD And White Front Glass Replacement 6091l-1402C

$17.99



A1618 NEW OEM Battery for MacBook Pro 15

A1618 NEW OEM Battery for MacBook Pro 15" Retina A1398 Mid 2015 020-00079

$43.90



Genuine A1417 OEM Battery Apple Macbook Pro 15 Retina A1398 Mid 2012 Early 2013 picture

Genuine A1417 OEM Battery Apple Macbook Pro 15 Retina A1398 Mid 2012 Early 2013

$40.90



NEW OEM Battery A1466 A1369 A1496 A1405 A1377 A1466 for MacBook Air 13 inch picture

NEW OEM Battery A1466 A1369 A1496 A1405 A1377 A1466 for MacBook Air 13 inch

$31.90



NEW OEM A1618 Battery for Apple MacBook Pro 15” Retina 99.5Wh A1398 Mid 2015 picture

NEW OEM A1618 Battery for Apple MacBook Pro 15” Retina 99.5Wh A1398 Mid 2015

$43.90



OEM Battery for MacBook Pro 17

OEM Battery for MacBook Pro 17" A1309 A1297 Early 2009 Mid 2009 2010 MC226

$40.90







Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.