Android Question Problem with HttpJob

tonyhunt

Member
Licensed User
Longtime User
Hi,
I am having a problem calling a small PHP code snippet with HttpJob.

The following manually entered URL works as anticipated.
http://www.martinsrubber.com/LocUser.php?Lon=-1.5192225&Lat=50.9278771&Imei=358032050172122

LocUser.php is a mature well used snippet of code known to work for the last 3 years.


The code which fails is as follows...

Sub Location_LocationChanged (Longitude As Double, Latitude As Double, Altitude As Double, Accuracy As Float, Bearing As Float, Provider As String, Speed As Float, time As Long)

Dim job2 As HttpJob
Dim sPHP As String
sPHP = "?Lon=" & Longitude & "&Lat=" & Latitude & "&Imei=" & cImei
' This line gives the sPHP string
'?Lon=-1.5192225&Lat=50.9278771&Imei=358032050172122
job2.Initialize("Job2", Me)
job2.PostString("http://www.martinsrubber.com/LocUser.php", sPHP)
Log(sPHP)
End Sub

The callback procedure JobDone gives the following error message..

JobName = Job2, Success = true //Job obviously runs ok but PHP Item String failing????
<br />
<b>Notice</b>: Undefined index: Lat in <b>E:\Domains\m\martinsrubber.com\user\htdocs\LocUser.php</b> on line <b>9</b><br />
<br />
<b>Notice</b>: Undefined index: Lon in <b>E:\Domains\m\martinsrubber.com\user\htdocs\LocUser.php</b> on line <b>10</b><br />
<br />
<b>Notice</b>: Undefined index: Imei in <b>E:\Domains\m\martinsrubber.com\user\htdocs\LocUser.php</b> on line <b>11</b><br />


Is job2.PostString("http://www.martinsrubber.com/LocUser.php", sPHP) Incorrect anywhere??

I always assume things are my fault, so if it's very obvious what I'm doing wrong, please don't spare my blushes..

Best Wishes

Tony Hunt
 

DonManfred

Expert
Licensed User
Longtime User
Notice
Undefined index: Lat in LocUser.php on line <b>9</b>
Undefined index: Lon in LocUser.php on line <b>10</b>
Undefined index: Imei in LocUser.php on line <b>11</b>

You use an Arrayindex which is not set in the array.
e g
$lat = $somearray[index];

You should use $somearray['index'] or you should supress Notices in the php-error-level.
 
Upvote 0

tonyhunt

Member
Licensed User
Longtime User
I don't think I use arrays in any of the code.

I'm simply creating a simple string eg: ?Lon=-1.5192225&Lat=50.9278771&Imei=358032050172122
to pass to the PHP function.

If I trap the string in the debugger, copy and paste into a web browser eg:

http://www.martinsrubber.com/LocUser.php?Lon=-1.5192225&Lat=50.9278771&Imei=358032050172122

This works well. As indeed the php code has done for the last 3 years..


Perhaps it is possible to find what string is being passed by the job2.PostString(..... function??

Best Wishes

Tony Hunt
 
Upvote 0

tonyhunt

Member
Licensed User
Longtime User
Thanks a lot for that. print_r($_REQUEST);

Now I'm confused, this gives the result
Array
(
[?Lon] => -1.5191936
[Lat] => 50.9278917
[Imei] => 358032050172122
)

I have been using print_r($_SERVER['QUERY_STRING']);
this gives a result I was expecting: Lon=-1.5192225&Lat=50.9278771&Imei=358032050172122
In the PHP I am then extracting the variables like this:

$Lat = $_GET["Lat"];
$Lon = $_GET["Lon"];
$Imei = $_GET["Imei"];

How do I get the variables from an array in PHP?

Best Wishes

Tony Hunt
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
To be sure the vars comes via GET you could use an

PHP:
print_r($_GET);

or maybe the comes as POST then it should be

PHP:
print_r($_POST);

THEN you KNOW in which array they are.

If you know then you can use

PHP:
$Lat = $_GET["Lat"];
$Lon = $_GET["Lon"];
$Imei = $_GET["Imei"];

or

PHP:
$Lat = $_POST["Lat"];
$Lon = $_POST["Lon"];
$Imei = $_POST["Imei"];
 
Upvote 0

tonyhunt

Member
Licensed User
Longtime User
Thank you very much for your assistance.

>>BTW: [?Lon] is not ok for an array-entry... There is something wrong...
Just a bizarre idea I had because this works in a browser. (WITH a ?)
http://www.martinsrubber.com/LocUser.php?Lon=-1.5192225&Lat=50.9278771&Imei=358032050172122

The ? has gone now...

I have tried The method :
PHP:
$Lat = $_REQUEST['Lat'];
$Lon = $_REQUEST['Lon'];
$Imei = $_REQUEST['Imei'];
This works as expected AND I understand it now.

You have been a great help and very patient.

Best Wishes

Tony Hunt
 
Upvote 0
Top