Android Question B4A / PHP

MarcoRome

Expert
Licensed User
Longtime User
Hi all i have this code in B4A:

B4X:
Sub ExecuteRemoteQuery(Query As String, JobName As String)
    Dim job As HttpJob
    job.Initialize(JobName, Me)
    job.PostMultipart("http://www.xxxx.eu/yyyy/dbpwtestmultipart.php", CreateMap("pw":marco), Null )
End Sub

Sub JobDone(Job As HttpJob)
    ProgressDialogHide
    If Job.Success Then
    Dim res As String
        res = Job.GetString
        Log("Response from server: " & res)
    Else
         Log( Job.ErrorMessage)
     End If
    Job.Release
End Sub

This is code PHP (dbpwtestmultipart.php):

B4X:
<?

$check = $_POST["pw"];

if ($check == "marco"){
     echo "entro";
    }
else
    {
echo "Error";
echo $pw;
}
?>

Res return anyway "Error" also if $pw is = marco
Any idea ?
Thanks
Marco
 

DonManfred

Expert
Licensed User
Longtime User
and the variable marco is a string and holds "marco"?

B4X:
    Dim job As HttpJob
  job.Initialize("Login", Me)
  job.PostMultipart("http://www.basic4android.de/example.php", CreateMap("pw":"test"),
example.php holds your php-code (not exactly;$pw at the end is replaced by $check)...
This is the - expected - result
Response from server: Errortest
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
and the variable marco is a string and holds "marco"?

B4X:
    Dim job As HttpJob
  job.Initialize("Login", Me)
  job.PostMultipart("http://www.basic4android.de/example.php", CreateMap("pw":"test"),
example.php holds your php-code (not exactly;$pw at the end is replaced by $check)...
This is the - expected - result
Sorry Don i forget that i have this code in Global
B4X:
Dim marco as String = "marco"
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Ok, tried it with a global...

This php works for me
Please note that i replaced the " with ' in setting $check
B4X:
<?
error_reporting(E_ALL ^ E_NOTICE);
#print_r($_REQUEST);
$check = trim($_POST['pw']);

if ($check == "marco"){
    echo "entro";
} else {
    echo "Error";
    echo $check;
}
?>

** Activity (main) Pause, UserClosed = true **
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (httputils2service) Create **
** Service (httputils2service) Start **
Response from server: entro
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **

Refer to this for more informations about single and double quotes
 
Last edited:
Upvote 0

Ormente

Member
Licensed User
Longtime User
My Pleasure.

The difference between " and ' in PHP can be summarized as follows :

PHP:
<?php
    $var = 'COOL';
    echo 'B4A IS $var\n'; // prints exactly: B4A IS $VAR\n
    echo "B4A IS $var\n"; // prints : B4A IS COOL followed by a newline
?>
 
Upvote 0
Top