Communicating with B4A using a parameterized PHP file

jddiven

Member
Licensed User
Longtime User
I've been trying to develop a B4A app that draws data from and stores data to a MySQL database using a parameteratized PHP file.

The first segement in my PHP file accepts and activity parameter and an ID parameter and returns dat through a SQL select statement. Below is the code.

PHP:
<?php
$mysqlDatabaseName = "192.168.1.***";
$mysqlUsername = "root";
$mysqlPassword = "****";

mysql_connect($mysqlDatabaseName, $mysqlUsername, $mysqlPassword) or die(mysql_error());
mysql_select_db("Inventory") or die(mysql_error());

if(isset($_GET['action'])){
   $action = $_GET['action'];
}

if($action == "fetch"){
   
      $fetchKey = $_GET['ID'];
   

      $result = mysql_query("SELECT nomenclature,location, part_number, date_inventoried,quantity,location_detail FROM tblInventory WHERE tblInventory.key = '$fetchKey'" ) or die(mysql_error());

   
      $rows = array();
      while($row = mysql_fetch_array($result)){
         $rows[] = $row ['nomenclature'];
         $rows[] = $row ['location'];
         $rows[] = $row ['part_number'];
         $rows[] = $row ['date_inventoried'];
         $rows[] = $row ['quantity'];
         $rows[] = $row ['location_detail'];
      }         
      
   echo json_encode($rows);
   
}
?>

This works fine using a browser (See Attached jpg) but I haven't been able to tie it to my B4A program. I've tried both a req.InitializeGet statement and using the ExecuteRemoteQuery sub from Erol's example. In both cases something runs and I'm transferred to the httpResponseSuccess sub but get indication the the result is empty.

What do I need to do?

Thanks for your help.

Doug
 

Attachments

  • PHP Result 092612.JPG
    37.2 KB · Views: 210
  • inventory.php.txt
    898 bytes · Views: 167

jddiven

Member
Licensed User
Longtime User
At this point my code is pretty much spaghetti. Here's the barcode found sub that sends the request.

B4X:
Sub myABBarcode_BarcodeFound (barCode As String, formatName As String)
   Dim req As HttpRequest
   'Dim job1 As HttpJob
   Label1.Text = barCode
   mResult = barCode
   'ProgressDialogShow("Getting Information")
   'ExecuteRemoteQuery("SELECT nomenclature,location, part_number, date_inventoried, quantity, location_detail FROM tblInventory WHERE tblInventory.key = '" & mResult & "'", SCANNED_ITEM)
   'req.InitializePost2("http:\\192.168.1.117\INVENTORY.php","action=fetch&ID="&mResult.GetBytes("UTF8"))
   req.InitializeGet("http:\\192.168.1.117\Inventory.php?action=fetch&ID="&mResult)
   'hc.Execute(req,1)
   'job1.Initialize("Job1",Me)
   'job1.PostString("http://192.168.1.117/Inventory.php","Activity=fetch&ID="&mResult)
End Sub

If I run the program with the InitializeGet What I get is "An error has occurred in sub: main_myabbarcode_barcodefound(java line:381)
java.lang.IllegalArgumentException:Illegal character in schemeSpecificPart at Iindex 5:http:\\192.168.1.117\Inventory.php?action=fetch&ID=3990"

Thank you for your help.

Doug
 

Attachments

  • bc return sub.txt
    728 bytes · Views: 163
  • hc response success.txt
    1.6 KB · Views: 176
Upvote 0

timwil

Active Member
Licensed User
Longtime User
Here is what I do to connect my b4a to a php server with mysql
 

Attachments

  • Example.zip
    64.9 KB · Views: 235
Upvote 0

jddiven

Member
Licensed User
Longtime User
Problem Solved

Thank you Erel & TimWil. Your input was helpful in getting me past "my hump".

Thanks Again!
 
Upvote 0

timwil

Active Member
Licensed User
Longtime User
You are welcome!

Someone helped me get started - so i have to help others

good luck with your project
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…