HttpClient one again ...

Allezom06

Member
Licensed User
Longtime User
Hello

Please help me...
this code don't work
Why ?


Sub Process_Globals
Dim hc As HttpClient
Dim Requete As String
End Sub
Sub btn_GagnantEnvoyer_Click
Requete = "INSERT INTO pingpong.scores (`joueur1`) VALUES ('moi')"
Dim req As HttpRequest
req.InitializePost2("http://192.168.1.103/pingpong.php", Requete.GetBytes("UTF8"))
hc.Execute(req, 1)
End Sub

Sorry for my poor english ...

http://192.168.1.103/pingpong.php?query=INSERT INTO pingpong.scores (`joueur1`) VALUES ('moi') ==> OK
 

mc73

Well-Known Member
Licensed User
Longtime User
Shouldn't you add
B4X:
query=
at the beginning of 'Requete' variable?
 
Upvote 0

Allezom06

Member
Licensed User
Longtime User
it's the same. One other idea ?

my pingpong.php:


<?php
$link = mysql_connect("localhost", "pingpong", "pingpong")
or die("Impossible de se connecter : " . mysql_error());
$sql = $_GET["query"];
$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
mysql_close($link);
?>
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
In your php I see thar you are using the get method, not the post one.
 
Upvote 0

Allezom06

Member
Licensed User
Longtime User
If i use new pingpong.php with "POST" , "http://192.168.1.103/pingpong.php?query=INSERT INTO pingpong.scores (`joueur1`) VALUES ('moi')", i've this error

New pingpong.php:

<?php
$link = mysql_connect("localhost", "pingpong", "pingpong")
or die("Impossible de se connecter : " . mysql_error());
$sql = $_POST["query"];
$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
mysql_close($link);
?>

Error :

( ! ) Notice: Undefined index: query in C:\wamp\www\pingpong.php on line 4
Call Stack
# Time Memory Function Location
1 0.0007 367224 {main}( ) ..\pingpong.php:0
Erreur SQL !

Query was empty

And if I use this pingpong.php

<?php
$link = mysql_connect("localhost", "pingpong", "pingpong")
or die("Impossible de se connecter : " . mysql_error());
$sql = $_GET["query"];
$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
mysql_close($link);
?>

It's ok with "http://192.168.1.103/pingpong.php?query=INSERT INTO pingpong.scores (`joueur1`) VALUES ('moi')" but I've this error whit basic4android code:

... Notice: Undefined index: query in C:\wamp\www\pingpong.php on line <i>4</i></th></tr> ... Erreur SQL !<br><br>Query was empty
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
I suggest you read the mysql tutorial, in case you haven't done it already. There, you will find the generic approach, you set up a generic.php on the server side, while you execute a remote query at the client's side.

In your case now. The two sides, client and server should use the same method. If you use 'get' on the client's side, use 'get' in your php too. If you use 'post', the same. Writing '?query=...' means that you are using the 'get' method, not the 'post' one. That's fine, you should use initializeGet. Still, I strongly suggest that you follow the approach of the tutorial. It's very reliable, at least I use it without any problems so far.


Finally, you can have a look at another tutorial, since I see that you want to inject scores. Here.
 
Upvote 0

Allezom06

Member
Licensed User
Longtime User
Thanks for all,
I've allready read the tutorial ,but now, l'll see my configuration WAMP (Apache, PHP, MSQL servers) . It seems that my problem is since a live update of one of the component but i'm not sure...
Thanks and have a good day.
Best regards
 
Upvote 0
Top