Android Question problem with httputils2 in need of help

jchal

Active Member
Licensed User
Longtime User
i am trying to store some valuses in database
my database is as follows
upload_2016-3-15_0-28-43.png

my code
#Region Module Attributes
#FullScreen: False
#IncludeTitle: True

#End Region

Sub Process_Globals
Dim GPS1 As GPS
Dim currentURL As String

End Sub

Sub Globals
Dim lblLon As Label
Dim lblLat As Label
Dim lblSpeed As Label
Dim lblSatellites As Label
Dim mybatlevel As Int
Dim mylat As Double
Dim mylong As Double
Dim myspeed As Int
Dim mydate As EditText
Dim mytime As EditText
Dim myusername As EditText

Private btnLogout As Button
Private lblMessage As Label

Private bat_lvl As Label
Dim hg As PhoneEvents
End Sub

Sub Activity_Create(FirstTime As Boolean)


If FirstTime Then
GPS1.Initialize("GPS")
End If
Activity.LoadLayout("frmtracking")
lblMessage.Text = "Welcome, " & Login.strUserName
ToastMessageShow(currentURL, False)
'for battery
hg.Initialize("hg")
End Sub
Sub hg_BatteryChanged (Level As Int, Scale As Int, Plugged As Boolean, Intent As Intent)
bat_lvl.Text = "Battery = " & Level & "%"
mybatlevel=Level
End Sub
Sub Activity_Resume
If GPS1.GPSEnabled = False Then
ToastMessageShow("Please enable the GPS device.", True)
StartActivity(GPS1.LocationSettingsIntent) 'Will open the relevant settings screen.
Else
GPS1.Start(0, 0) 'Listen to GPS with no filters.
End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)
GPS1.Stop
End Sub

Sub GPS_LocationChanged (Location1 As Location)
DateTime.dateformat = "yyyy/MM/dd"
DateTime.TimeFormat= "HH:MM:SS"
mylat=Location1.Latitude
mylong=Location1.Longitude
myusername= Login.strUserName


lblLat.Text = "Lat = " & Location1.ConvertToMinutes(Location1.Latitude)
lblLon.Text = "Lon = " & Location1.ConvertToMinutes(Location1.Longitude)
lblSpeed.Text = "Speed = " & (Location1.Speed * 3.6)

myspeed= Location1.Speed * 3.6
mydate=DateTime.date(DateTime.now)
mytime=DateTime.Time(DateTime.Now)

Dim InsertNewPossition As HttpJob
InsertNewPossition.Initialize("InsertNewPossition", Me)
InsertNewPossition.download2("http://www.mydomainname.com/gpsstore.php", Array As String ("action", "InsertNewPossition", "user_name", myusername, "date", mydate, "time", mytime,"latitude", mylat, "longitude", mylong,"speed", myspeed ,"battery", mybatlevel))
Msgbox("saved", myusername)
End Sub

Sub GPS_UserEnabled (Enabled As Boolean)
ToastMessageShow("GPS device enabled = " & Enabled, True)
End Sub

Sub GPS_GpsStatus (Satellites As List)
lblSatellites.Text = "Satellites:" & CRLF
For i = 0 To Satellites.Size - 1
Dim Satellite As GPSSatellite
Satellite = Satellites.Get(i)
lblSatellites.Text = lblSatellites.Text & CRLF & Satellite.Prn & _
" " & Satellite.Snr & " " & Satellite.UsedInFix & " " & Satellite.Azimuth _
& " " & Satellite.Elevation
Next
End Sub
Sub JobDone(Job As HttpJob)
ProgressDialogHide
If Job.Success Then
Dim res As String
res = Job.GetString
Log("Back from Job:" & Job.JobName )
Log("Response from server: " & res)

Dim parser As JSONParser
parser.Initialize(res)

Select Job.JobName


Case "InsertNewPossition"
'Do nothing

End Select


Else
ToastMessageShow("Error: " & Job.ErrorMessage, True)
End If
Job.Release
End Sub
and the gpsstore.php code is the following

<?
$host = "localhost";
$db = "mydb";
$user = "myuser";
$pw = "1234";
//include ("db.php");
$con = mysql_connect($host,$user,$pw) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());
mysql_query("SET CHARACTER SET utf8");

$action = $_GET["action"];

switch ($action)

{
case "CountPosistions":
$q = mysql_query("SELECT * FROM tbl_track");
$count = mysql_num_rows($q);
print json_encode($count);
break;

Case "GetPossition":
$q = mysql_query("SELECT * FROM tbl_track");
$rows = array();
while($r = mysql_fetch_assoc($q))
{
$rows[] = $r;
}
print json_encode($rows);
break;

case "InsertNewPossition":
$user_name= $_GET["user_name"];
$date= $_GET["date"];
$time= $_GET["time"];
$latitude= $_GET["latitude"];
$longitude= $_GET["longitude"];
$speed= $_GET["speed"];
$battery= $_GET["battery"];


$q = mysql_query("INSERT INTO tbl_track (user_name, date, time, latitude, longitude, speed, battery) VALUES ('$user_name', '$date', '$time', '$latitude', '$longitude', '$speed', $battery' )");
print json_encode("Inserted");
break;

}



?>
What do i make wrong?:confused::confused::confused::confused::confused::confused:
 

Brian Robinson

Active Member
Licensed User
Longtime User
Firstly, I think you should read through the rules about posting questions.
1. How to add code
2. You don't state what is "wrong" - what is the error message.
3. What is your expected outcome

If you want to see what is going wrong, you should log what the SQL is that it is running in PHP, and then try to run that SQL in PHPAdmin and it will give you a better clue as to what is wrong.

Without delving too deep the first problem i see is
$battery'

You are missing the quote mark at the start of this variable

The quotes are also only required if you are outputting string values (Not date, time, latitude, longitude speed and battery)

Also, you don't need to json_encode your result and can simply send it back as string.

Cheers
Brian
 
Upvote 0

jchal

Active Member
Licensed User
Longtime User
Hi guys I have shorted it out.
It was the '
Thanks a lot!!!!
Please remember I am new and I am a learner so any advice or comment I welcome !!!!!
 
Upvote 0
Top