Android Question Send data from b4a to php

Isac

Active Member
Licensed User
Longtime User
hi, how can I send a value to a php page?

for example:



HTML:
<html>
<body>
............
name:
<input type="text" name="name"/>
.............
</body>
</html>


PHP:
<html>
<body>

<?php
$myname=$_POST["name"];
?>

</body>
</html>

Thanks for the attention
 
Last edited:

Isac

Active Member
Licensed User
Longtime User
But to send data to a php page, I can use Webview? or are there other solutions?
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
But to send data to a php page

a) If you just want to create a webpage using php you don't need an app at all. Just start your stock browser and call the page you've created.

b) If you want to let the user enter some values in f.e. Edittext's and send those to a php script, then use OkHttpUtils to send the data (see my signature for an example). Here you only need the php script, no html.
 
Upvote 0

Isac

Active Member
Licensed User
Longtime User
but if I have a website with a page php and I would use B4A to send data to this page? I always use HttpUtils? thank you
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
but if I have a website with a page php and I would use B4A to send data to this page? I always use HttpUtils? thank you

Yu can to send data in 2 way ( GET or POST ):

B4A
B4X:
'Send a GET request
job1.Download2("http://www.b4x.com/print.php", _
      Array As String("user_id", "first value :)", "age", "value 2"))

'Send a POST request
 job2.Initialize("Job2", Me)
 job2.PostString("http://www.b4x.com/print.php", "user_id=first value&age=value2")

PHP
B4X:
....
$uid = mysql_real_escape_string($_GET["user_id"]);
$age = mysql_real_escape_string($_GET["age"]);
$query = "SELECT Name, Surname FROM user where UserBase_Id = '$uid' and Age=$age";
.....

$uid = $_POST["user_id"];
$query = "SELECT Name, Surname FROM user where UserBase_Id = '$uid' and Age=$age";
 
Upvote 0

Isac

Active Member
Licensed User
Longtime User
a) If you just want to create a webpage using php you don't need an app at all. Just start your stock browser and call the page you've created.

b) If you want to let the user enter some values in f.e. Edittext's and send those to a php script, then use OkHttpUtils to send the data (see my signature for an example). Here you only need the php script, no html.

excuse me, where can I find your example to send a EditText?

thank you
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
excuse me, where can I find your example to send a EditText?
See his signature.
He has posted some tutorials on how to work with php and okhttp

Note that you do send the TEXT entered inside the edittext, not the edittext.

See httputils tutorials. Search forum; there are hundrets of posts...
 
Upvote 0

Isac

Active Member
Licensed User
Longtime User
I need your help :confused:, the php code where I write?

I currently write the php code only in the web page


PHP:
<html>
<body>

<?php
$myname=$_POST["name"];
?>

</body>
</html>


Sub jobdone (Job As HttpJob) what is it?

Honestly I did not understand how to do, it is not very easy.

thank






B4X:
#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: False
#End Region

Sub Process_Globals

End Sub

Sub Globals

Private EditText1 As EditText 
Private Button1 As Button
Dim job2 As HttpJob
 
 
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("test")

End Sub
Sub Activity_Resume


End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click
 
    Dim name As String = EditText1.Text
    If name = "" Then
        Msgbox("Please enter Name", "Error")
        Return 
    End If
'Send a POST request
  job2.Initialize("Job2", Me)
  job2.PostString("http://.............../test.php", "EditText1.Text=name")
'    Dim register As HttpJob
'    register.Initialize("register", Me)
'    register.Download2("http://trycatch.altervista.org/primo.php", _
'      Array As String("name", EditText1.Text))
End Sub 




Sub JobDone (Job As HttpJob)
Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
  If Job.Success = True Then
      Select Job.JobName
        Case "Job1", "Job2"
            'print the result to the logs
            Log(Job.GetString)
        Case "Job3"
            'show the downloaded image
            Activity.SetBackgroundImage(Job.GetBitmap)
      End Select
  Else
      Log("Error: " & Job.ErrorMessage)
      ToastMessageShow("Error: " & Job.ErrorMessage, True)
  End If
  Job.Release
End Sub
 
Upvote 0
Top