In my program i use initializePost2 (HTTP) for all my requests. INSERT, SELECT - work fine, but when I try using DELETE - internal server error occurs:
DELETE * FROM barcodes\nYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* FROM barcodes' at line 1
Here is the code:
And PHP:
DELETE * FROM barcodes\nYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* FROM barcodes' at line 1
Here is the code:
B4X:
'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim hc As HttpClient
End Sub
Please help.
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim tabhoster As TabHost
Dim pnl1,pnl2,pnl3 As Panel
Dim clear As Button
Dim scan As Button
Dim tbl As table
Dim id As Label
Dim bcreader As ABZxing
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
hc.Initialize("hc")
End If
tabhoster.Initialize("tabhoster")
pnl1.Initialize("pnl1")
pnl2.Initialize("pnl2")
pnl3.Initialize("pnl3")
tbl.Initialize(pnl3,"tbl",2)
id.Initialize("id")
clear.Initialize("clear")
scan.Initialize("scan")
pnl1.AddView(clear,20%x,30%y,60%x,15%y)
pnl2.AddView(scan,20%x,30%y,60%x,15%y)
pnl2.AddView(id,scan.Left,scan.Top+scan.Height+5%y,10%x,10%y)
tbl.AddToPanel(pnl3,0,0,100%x,100%y)
tabhoster.AddTab2("Service",pnl1)
tabhoster.AddTab2("Scan",pnl2)
tabhoster.AddTab2("Table",pnl3)
Activity.AddView(tabhoster,0,0,100%x,100%y)
tbl.SetHeader(Array As String("ID","Barcode"))
clear.Text="Clear"
scan.Text="Scan"
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub scan_click
bcreader.ABGetBarcode("bcreader","")
End Sub
Sub BCREADER_BarcodeFound (barCode As String, formatName As String)
ExecuteRemoteQuery("INSERT INTO barcodes (id, barcode) VALUES (NULL, '"&barCode&"')",1)
End Sub
Sub ExecuteRemoteQuery(Query As String, TaskId As Int)
Dim req As HttpRequest
req.InitializePost2("http://xxx.xxx.xx.xxx/b4aconnector.php", Query.GetBytes("UTF8"))
hc.Execute(req, TaskId)
End Sub
Sub tabhoster_TabChanged
tbl.ClearAll
ExecuteRemoteQuery("SELECT * FROM barcodes",2)
End Sub
Sub hc_ResponseSuccess (Response As HttpResponse, TaskId As Int)
Dim res As String
res = Response.GetString("UTF8")
Log("Response from server: " & res)
Dim parser As JSONParser
parser.Initialize(res)
Select TaskId
Case 2
Dim barcodes As List
barcodes = parser.NextArray 'returns a list with maps
If barcodes.Size=0 Then
Msgbox("No values","Table is empty")
Return
End If
For i = 0 To barcodes.Size - 1
Dim m As Map
m = barcodes.Get(i)
tbl.AddRow(Array As String(m.Get("id"),m.Get("barcode")))
Next
End Select
ToastMessageShow("Таблица НЕ пуста",False)
Response.Release
End Sub
Sub hc_ResponseError (Response As HttpResponse, Reason As String, StatusCode As Int, TaskId As Int)
Log("Error: " & Reason & ", StatusCode: " & StatusCode)
If Response <> Null Then
Log(Response.GetString("UTF8"))
Response.Release
End If
End Sub
Sub clear_click
'Error!
ExecuteRemoteQuery("DELETE * FROM barcodes",3)
And PHP:
PHP:
<?
$databasehost = "localhost";
$databasename = "testdb";
$databaseusername ="xxx";
$databasepassword = "xxxxxxxxxx";
$con = mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());
mysql_select_db($databasename) or die(mysql_error());
$query = file_get_contents("php://input");
$sth = mysql_query($query);
if (mysql_errno()) {
header("HTTP/1.1 500 Internal Server Error");
echo $query.'\n';
echo mysql_error();
}
else
{
$rows = array();
while($r = mysql_fetch_assoc($sth)) {
$rows[] = $r;
}
print json_encode($rows);
}
?>