PHP - B4A Issue

jddiven

Member
Licensed User
Longtime User
I'm trying to set up a B4A program that uses paramaterized PHP to request and receive information from a MySQL database.

This is my PHP code
PHP: Copy
<?php
$mysqlDatabaseName = "192.168.1.***";
$mysqlUsername = "****";
$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);
   
}
?>

I can access what I want through a browser

(See attached Thumbnail) but haven't been able to successfully call and retrieve through B4A. I've tried to use req.InitializeGet as well as the ExecuteRemoteQuery procedure from Erel's example. The program executes something and returns to the hc_ResponseSuccess sub but in both cases the result is empty.

How can I get this to work?

Thanks for your help.

Doug
 

Attachments

  • PHP Result 092612.JPG
    PHP Result 092612.JPG
    37.2 KB · Views: 459
  • inventory.php.txt
    inventory.php.txt
    898 bytes · Views: 379
Last edited:
Thanks for the suggestion!

I added the two HttpUtils2 code modules and tried the following code.

Code: Copy
Sub myABBarcode_BarcodeFound (barCode As String, formatName As String)
   Dim req As HttpRequest
   Dim job1 As HttpJob
   Label1.Text = barCode
   mResult = barCode
   job1.Initialize("Job1",Me)
   job1.PostString("http://192.168.1.117/Inventory.php","?Activity=fetch&ID="&mResult)
End Sub

Sub JobDone(Job As HttpJob)
   Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
   Log(Job.GetString)
End Sub

The log returns "JobName = Job1, Success = true" but no data is returned.

I suspect that I'm not calling PostString correctly but am not sure how it should be called.

Any thoughts?

Thank you for your help!

Doug
 

Attachments

Upvote 0
You don't need to put the '?' character on parameters field.

Code: Copy
job1.PostString("http://192.168.1.117/Inventory.php","Activity=fetch&ID="&mResult)
 
Upvote 0
Thanks for the suggestion.

I tried it without the question mark but the same thing happened.

What else can it be?
 
Upvote 0
Sorry! After I posted this one I couldn't find it and posted the other. I'll be more careful in the future. I really do appreciate all your help and don't want to abuse the system.
 
Upvote 0
Back
Top