Android Question reading from database i get internal servel error

jchal

Active Member
Licensed User
Longtime User
hi all i am trying to read from database i have created the php file and my activity
my activity is the following
B4X:
#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim strUserID As String
    Dim strUserName As String

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private ListView1 As ListView
    Private btnLogout As Button
    Private lblMessage As Label
       Private lblMessage As Label

End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Dim readtbl As HttpJob

    Activity.LoadLayout("frmtrackead")
    lblMessage.Text = "Welcome, " & Login.strUserName
    'ToastMessageShow(currentURL, False)

    readtbl.Initialize("readtbl", Me)
    readtbl.Download2("http://www.myweserver.com/readtracktbl.php", _
    Array As String("user_id", Login.strUserID))
    ProgressDialogShow("Connecting to server...")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub JobDone (Job As HttpJob)
    ProgressDialogHide
    If Job.Success = True Then
        Dim strReturn As String = Job.GetString
        Dim parser As JSONParser
        parser.Initialize(strReturn)
        If Job.JobName = "readtbl" Then
            Dim mytrack As List
            Dim strOnline As String
            mytrack = parser.NextArray 'returns a list with maps
            For i = 0 To mytrack.Size - 1
                Dim t As Map
                t = mytrack.Get(i)
                Dim TL As TwoLines
          
                TL.First = t.Get("user_id") & t.Get("date") & t.Get("time")
                TL.Second = t.Get("longitude") & t.Get("latitude")
                ListView1.AddTwoLines2(TL.First, TL.Second, TL)
          
          
            Next
        Else If Job.JobName = "LogOut" Then
            Dim act As String = parser.NextValue
            If act = "LoggedOut" Then
                ToastMessageShow("Logout successful", True)          
                StartActivity(Main)
                Activity.Finish
            End If          
        Else
            ToastMessageShow("Error: Invalid Value", True)
        End If
    Else
        'Log("Error: " & Job.ErrorMessage)
        ToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
    Job.Release
End Sub

and my php is the following, the php file is named readtracktbl.php

B4X:
<?
$host = "localhost";
$db = "mydb";
$user = "myuser";
$pw = "123";

$con = mysql_connect($host, $user, $pw) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());
mysql_query("SET CHARACTER SET utf8");
mysql_query("SET NAMES 'utf8'");

$uid = mysql_real_escape_string($_GET["user_id"]);

$res = mysql_query("SELECT user_id, date , time , latitude , longitude FROM tbl_track WHERE user_id = '$uid'");
if (!$res) {
    print json_encode("Error");
    echo "<br />" . mysql_error();
    exit;
}
else {
    if (mysql_num_rows($res) == 0) {
        print json_encode("Not Found");
        exit;
    }
    $row = mysql_fetch_row($res);

    }
    else {
        print json_encode($row[0]);
    }
}
?>
the error i get is internal server error
i dont get it on the app but i get it when i debug the app ( i see it in the variable ToastMessageShow("Error: " & Job.ErrorMessage, True) ).
what i am making wrong , is it in php my errors?
where as debugger does not help me, app seems to run smooth.
 
Last edited:

jchal

Active Member
Licensed User
Longtime User
the code tags are done.
th log does not give anything i just get this error message , i know it must be php but where is the error erel?
in server logs i found this line
[28-Mar-2016 14:33:11 UTC] PHP Parse error: syntax error, unexpected 'else' (T_ELSE) in /home/tracking/public_html/trackingmob/readtracktbl.php on line 28
 
Last edited:
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Erel, is right.

Just an almost off topic note. While you're in the process of creating and testing your php files, in my opinion you should always set in your php.ini the following
B4X:
error_reporting  =  E_ALL
display_errors = On
so that when an error occurs, it will be reported at the output, instead of, say, the 500 internal error.
 
Upvote 0
Top