Android Question PHP script with Parameters not working

erasmusackon

Member
Licensed User
Longtime User
This code is able to retrieve records from the server
B4X:
    $q = mysqli_query($con,"SELECT * FROM DepositTransactions");
    $rows = array();
    while($r = mysqli_fetch_assoc($q))
    {
    $rows[] = $r;
    }
    echo json_encode($rows);
    mysqli_close($con);

GetTransactions is unable to work. it returns [] when i checked the log. Am i doing anything wrong in this "GetTransactions"

B4X:
    Dim DownloanTransactions As HttpJob
    DownloanTransactions.Initialize("DownT", Me)
    DownloanTransactions.Download2(Server, Array As String ("action", "GetTransactions","memberID",MemberID,"lasttrans",LastTransID))

B4X:
$action = $_GET["action"];

switch ($action)

{
    case "CountPersons":
        $q = mysqli_query($con,"SELECT * FROM DepositTransactions WHERE MemberID=40001762");
        $count = mysqli_num_rows($q);
        print json_encode($count);
        mysqli_close($con);
    break;
  
    Case "GetTransactions":
        $memberid = $_GET["memberid"];
        $lasttrans = $_GET["lasttrans"];
        $q = mysqli_query($con,"SELECT * FROM DepositTransactions WHERE MemberID=$memberid AND TranNo>$lasttrans");
        $rows = array();
        while($r = mysqli_fetch_assoc($q))
        {
        $rows[] = $r;
        }
        print json_encode($rows);
        mysqli_close($con);
    break;
 
Last edited:

ronell

Well-Known Member
Licensed User
Longtime User
try this..
B4X:
"SELECT * FROM 'DepositTransactions' WHERE MemberID= '$memberid' AND TranNo> '$lasttrans'"
not tested
 
Upvote 0

erasmusackon

Member
Licensed User
Longtime User
try:

$q = mysqli_query($con,"SELECT * FROM DepositTransactions WHERE MemberID='$memberid' AND TranNo>'$lasttrans'");
Display $q to see if sql is well formed!
ECHO $q

Thanks @tigrot. This is the error am getting from the error log

<b>Parse error</b>: syntax error, unexpected '$rows' (T_VARIABLE), expecting ',' or ';' in <b>/home/sikasoft/public_html/app/newCon.php</b> on line <b>39</b><br />
 
Upvote 0

ronell

Well-Known Member
Licensed User
Longtime User
check the code before line 39 , you might miss a , or ; at the end of the line
--
let us see php code again
 
Upvote 0

erasmusackon

Member
Licensed User
Longtime User
I have modified the code and am now getting this "Response from server: []"
Not getting the actual data. is there anything wrong with my code?

B4X:
    Dim DownloanTransactions As HttpJob
    DownloanTransactions.Initialize("DownT", Me)
    DownloanTransactions.Download2(Server, Array As String ("action", "GetTransactions","memberID",MemberID,"lasttrans",LastTransID))

B4X:
$action = $_GET["action"];

switch ($action)

{
       Case "GetTransactions":
        $memberid = $_GET['memberid'];
        $lasttrans = $_GET['lasttrans'];
        $lasttrans= mysqli_real_escape_string($con, '$lasttrans');
        $memberid = mysqli_real_escape_string($con, '$memberid');
        $q = mysqli_query($con,"SELECT * FROM DepositTransactions WHERE MemberID='.$memberid.' AND TranNo>'.$lasttrans.'");
        $rows = array();
        while($r = mysqli_fetch_assoc($q))
        {
        $rows[] = $r;
        }
        print json_encode($rows);
        mysqli_close($con);
    break;
}
 
Upvote 0

erasmusackon

Member
Licensed User
Longtime User
post the whole updated php code, also the latest error ..

This code doesn't work but
B4X:
$q = mysqli_query($con,"SELECT * FROM DepositTransactions WHERE MemberID= '$memberid' AND TranNo>'$lasttrans'");

This code works and return the results. what might be the problem?
B4X:
$q = mysqli_query($con,"SELECT * FROM DepositTransactions WHERE MemberID= 40001762 AND TranNo>0");
 
Upvote 0

ronell

Well-Known Member
Licensed User
Longtime User
learn basic php , read/watch tutorials .. the problem is just simple.. you were just lacking knowledge about the basic of PHP
 
Upvote 0
Top