Android Question b4a and php codes not working after upgrading to b4a version 8.0

Gbenga Odumosu

Member
Licensed User
Longtime User
I have a project that retrieve information from database through php codes , but after upgrading to 8.0 b4a i started getting lots off errors or returning null as result or giving java.lang.RuntimeException: JSON array expected. i have done all i could without solution. is their anything i am not doing? help pls . I used example example giving by Kmatle in his tutorial
 

Attachments

  • b4php.zip
    8.5 KB · Views: 200

mcqueccu

Well-Known Member
Licensed User
Longtime User
Where is your php script too?

Anyway, check your database connection values in the php script. I tested the URL in the browser and I get access denied for the user.

Also, try and log the response from the server in the app, so that you will know how to handle it properly be it just a simple string or array or json object.
 
Upvote 0

Gbenga Odumosu

Member
Licensed User
Longtime User
Where is your php script too?

Anyway, check your database connection values in the php script. I tested the URL in the browser and I get access denied for the user.

Also, try and log the response from the server in the app, so that you will know how to handle it properly be it just a simple string or array or json object.

thanks for your reply this is my php code

<?

#include ("db.php");
#$host = "localhost";
#$user = "y";
#$pw = "a";
#$db = "tolu";

#$con = mysql_connect($host,$user,$pw) or die(mysql_error());

$con = mysqli_connect("localhost", "y", "a", "tolu");



// Check connection

if($con === false){

die("ERROR: Could not connect. " . mysqli_connect_error());

}

mysqli_query("SET CHARACTER SET utf8");

$action = $_GET["action"];

switch ($action)

{
case "CountPersons":
# print json_encode("just yap");
$q = mysql_query("SELECT * FROM persons");
$count = mysql_num_rows($q);
print json_encode($count);
break;

Case "GetPersons":
$q = mysql_query("SELECT name, age FROM Persons");
$rows = array();
while($r = mysqli_fetch_assoc($q))
{
$rows[] = $r;
}
print json_encode($rows);
break;

case "InsertNewPerson":
$name = $_GET["name"];
$age = $_GET["age"];
$q = mysqli_query("INSERT INTO Persons (name, age) VALUES ('$name', $age)");
print json_encode("Inserted");
break;

}





?>
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top