hello Erel,
I have problems with the http module, I can not send a query with parameters, for sure I lost a few pieces, but I have not figured out how to send parameters get or post to php.
I always return error :-(
I have problems with the http module, I can not send a query with parameters, for sure I lost a few pieces, but I have not figured out how to send parameters get or post to php.
I always return error :-(
B4X:
Dim linkpage As String = "http://xxxx.eu/ivano/xxxx.php"
Dim variables As String = "?command=freeQuery&q="
Dim s As String
If Mod_Global.register = False Then
s = "INSERT INTO user (name, lastname, phone, email, city, password, nik, idphone) VALUES ('" & tx1.Text & "', '" & tx2.Text & "', '" & tx3.Text & "', '" & tx4.Text & "', '" & tx5.Text & "', '" & tx6.Text & "', '" & tx7.Text & "', '" & Mod_Global.GetDeviceId & "')"
Else
s = "UPDATE user SET name='" & tx1.Text & "', " & _
"lastname='" & tx2.Text & "', " & _
"phone='" & tx3.Text & "', " & _
"email='" & tx4.Text & "', " & _
"city='" & tx5.Text & "', " & _
"password='" & tx6.Text & "', " & _
"nik='" & tx7.Text & "' " & _
"WHERE idphone='" & Mod_Global.GetDeviceId & "'"
End If
Dim job1cli As HttpClient
Dim job1req As HttpRequest
Log(linkpage & variables & s)
job1req.InitializeGet(linkpage & variables & s)
job1cli.Initialize("job1cli")
job1cli.Execute(job1req,1)
B4X:
Sub job1cli_ResponseSuccess(Response As HttpResponse, TaskId As Int)
Msgbox("Dati salvati","Login")
Mod_Global.name = tx1.Text
Mod_Global.lastname = tx2.Text
Mod_Global.numberphone = tx3.Text
Mod_Global.emailaddress = tx4.Text
Mod_Global.city = tx5.Text
Mod_Global.password = tx6.Text
Mod_Global.nik = tx7.Text
Mod_Global.idphone = Mod_Global.GetDeviceId
End Sub
B4X:
Sub job1cli_ResponseError(Response As HttpResponse, Reason As String, StatusCode As Int, TaskId As Int)
Dim Message As String
Log("Error UPDPOS: " & Reason & ", StatusCode: " & StatusCode)
If Response <> Null Then
Msgbox(Response.GetString2("UTF8"),"Error")
End If
End Sub
PHP:
<?php
$user="xxxxxx";
$password="xxxx";
$database="xxxx";
mysql_connect(localhost,$user,$password);
@mysql_select_db($database) or die( "Impossibile selezionare il database.");
$xq = (isset($_GET['q'])) ? $_GET['q'] : "" ;
$xcommand = (isset($_GET['command'])) ? $_GET['command'] : "" ;
if ( $xcommand == "" || $xq == "" ){
mysql_close($objConnect);
print "No Query or Parameter";
return;
}
$query=xq
mysql_query($query) or die( "Errore nella query. Query non eseguita.");
$intNumRows = mysql_num_rows($objQuery);
if ( $xcommand == "FreeQuery" ){
mysql_close($objConnect);
print mysql_errno().": ".mysql_error()."";
return;
}
if ( $intNumRows == null || $intNumRows = 0 ){
$error = mysql_errno().": ".mysql_error()."\n";
print $error;
mysql_close($objConnect);
return;
}
else
{
$rows = array();
while($r = mysql_fetch_assoc($objQuery ))
{
$rows[] = $r;
}
print json_encode($rows);
mysql_close($objConnect);
}
?>