Inserting Data to MySQL

Nickle

Member
Licensed User
Longtime User
I have used earlier sample (http://www.b4x.com/forum/basic4andr...-connect-android-mysql-database-tutorial.html) for mysql to access my data stored on mysql database and it works perfectly well. Now I am trying to post data using the same approach and accessing the same PHP script which is acting as a webservice. This runs fine without errors but nothing gets into the database table. I need help.

'ExecuteRemoteQuery("insert into table smslog values" & "(" & Address & "," & Body & "," & smsRead & "," & smsdate & "," & smstime & "1"")
ExecuteRemoteQuery("insert into smslog values('0266000059','Test SMS','Read','2012-10-23','10:20PM'",2)
End Sub

Sub ExecuteRemoteQuery(Query As String, TaskId As Int)
Dim req As HttpRequest
req.InitializePost2("http://192.168.1.24:10088/Countries/xountries.php", Query.GetBytes("UTF8"))
hc.Execute(req, TaskId)
End Sub
 

fanfalveto

Active Member
Licensed User
Longtime User
i do that and runs ok
B4X:
ExecuteRemoteQuery("http://32.3.4.3/android.php?id=" & id & "&fecha="&fecha&"&hora="&hora&"&nombre="&nombre&"&longitud=" &longitud&"&latitud="&latitud,1)
and php code
B4X:
<?
$databasehost = "localhost";
$databasename = "afichar";
$databaseusername ="root";
$databasepassword = "";

$con = mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());
mysql_select_db($databasename,$con) or die(mysql_error());

$id=$_GET['id'];
$fecha=$_GET['fecha'];
$hora=$_GET['hora'];
$nombre=$_GET['nombre'];
$longitud=$_GET['longitud'];
$latitud=$_GET['latitud'];

 $id = mysql_real_escape_string($id);
    $fecha = mysql_real_escape_string($fecha);
 $hora = mysql_real_escape_string($hora);
    $nombre = mysql_real_escape_string($nombre);
 $longitud = mysql_real_escape_string($longitud);
    $latitud = mysql_real_escape_string($latitud);

$sql="INSERT INTO horarios (id,fecha,hora,nombre,longitud,latitud) VALUES ('$id','$fecha','$hora','$nombre','$longitud','$latitud')";
mysql_query($sql);
$result=mysql_query($sql);
if($result==false){
 echo "query was: $sql";
 echo "<br>";
 echo mysql_error();
}  
?>
 
Upvote 0

fanfalveto

Active Member
Licensed User
Longtime User
sorry and this
B4X:
Sub ExecuteRemoteQuery(Query As String, TaskId As Int)
Dim req As HttpRequest
    req.InitializePost2(Query, Query.GetBytes("UTF8"))
   Msgbox(Query,"")
  hc.Execute(req, TaskId)
     ProgressDialogShow("Subiendo datos")
   ToastMessageShow(Query,True)
End Sub
 
Upvote 0

Nickle

Member
Licensed User
Longtime User
Thanks alot for the help, will try that now but before that I have another novis question. Where does

ExecuteRemoteQuery("http://32.3.4.3/android.php?id=" & id & "&fecha="&fecha&"&hora="&hora&"&nombre="&nombre&"&longitud=" &longitud&"&latitud="&latitud,1)

fit in your Android code
 
Upvote 0

djpero

Member
Licensed User
Longtime User
sorry and this
B4X:
Sub ExecuteRemoteQuery(Query As String, TaskId As Int)
Dim req As HttpRequest
    req.InitializePost2(Query, Query.GetBytes("UTF8"))
   Msgbox(Query,"")
  hc.Execute(req, TaskId)
     ProgressDialogShow("Subiendo datos")
   ToastMessageShow(Query,True)
End Sub

what is hc?
 
Upvote 0
Top