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


PANASONIC KX-NT553 Business IP Handset VoIP Office Phone picture

PANASONIC KX-NT553 Business IP Handset VoIP Office Phone

$49.99



Polycom Vvx 601 VoIP 16 Line Business Phone 4.3

Polycom Vvx 601 VoIP 16 Line Business Phone 4.3" HD Touchscreen PoE With Stand

$28.95



Allworx Verge 9312 Voip IP Color Display Phone 8113120 Gigabit w/ Stand (no PSU) picture

Allworx Verge 9312 Voip IP Color Display Phone 8113120 Gigabit w/ Stand (no PSU)

$99.00



Allworx Verge 9312 Voip IP Color Display Phone 8113120 Gigabit NO Stand (no PSU) picture

Allworx Verge 9312 Voip IP Color Display Phone 8113120 Gigabit NO Stand (no PSU)

$89.00



Allworx Verge 9312 Voip IP Color Display Phone 8113120 Gigabit & Backlit New picture

Allworx Verge 9312 Voip IP Color Display Phone 8113120 Gigabit & Backlit New

$249.99



Yealink SIP-T21P E2 IP Phone with Stand PoE Warranty VoIP Tested picture

Yealink SIP-T21P E2 IP Phone with Stand PoE Warranty VoIP Tested

$23.98







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