B4J Question Data from onlineDB B4A B4J diff results

tsteward

Well-Known Member
Licensed User
Ok why when I call the same php code from B4J or B4A it behaves differently.
When called from B4A it fetches the data just fine and updates the History table.

B4X:
("http://locksdownunder.atwebpages.com/codes2.php", Array As String ("Action", "FindCode","Mail",Routines.getMail,"ID",Main.phid.GetDeviceId,"Table",VehicleOnly.codeTable,"Code",EdTxtCode.Text))
When called from my B4J it fetches the data fine but will not update the History table.
B4X:
("http://locksdownunder.atwebpages.com/codes2.php", Array As String ("Action", "FindCode","Mail",Routines.getMail,"ID",Main.phid.GetDeviceId,"Table",VehicleOnly.codeTable,"Code",EdTxtCode.Text))
PHP Code
B4X:
<?
$host = "XXXX";
$db = "1833309_XXX";
$user = "1833309_XXX";
$pw = "XXXXX";

$con = mysql_connect($host,$user,$pw) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());
mysql_query("SET CHARACTER SET utf8");
mysql_query("SET NAMES 'utf8'");

$action = $_GET["Action"];
switch ($action)
    {
    case "FindCode":
        $mail=$_GET["Mail"];
        $id = $_GET["ID"];
        $table = $_GET["Table"];
        $code = $_GET["Code"];
        //look up code
        $q = mysql_query("SELECT * FROM table$table Where Code LIKE '%$code%' LIMIT 1");
        $count = mysql_num_rows($q);
        if ($count > 0) #if no match to email found in DB
        {
            $row = mysql_fetch_array($q);
            $result = $row['Bitting'];
            $res = mysql_query("Insert into history (email, regnr, transaction, date) VALUES ('$mail', $id, 'Looked up Code $code Table$table - Found', NOW())");
            print json_encode($result);
        }
        else
        {
            $res = mysql_query("Insert into history (email, regnr, transaction, date) VALUES ('$mail', $id, 'Looked up Code $code Table$table - NOT Found', NOW())");
            Print json_encode("Invalid Code");
        }
        break;
    }
?>

Doesnt make sence.
I have replaced the stings with text but still same issue.

Any ideas?
 

tsteward

Well-Known Member
Licensed User
OK so I have tracked the problem and although not a B4X problem i'm hoping you guys can help.

In the following php code if $id contains any alpha characters the insertion fails. It can only contain numerical character to succeed. See image of DB structure.
$res = mysql_query("Insert into history (email, regnr, transaction, date) VALUES ('$mail', $id, 'Looked up Code $code Table $table - Found', NOW())");

ScreenClip.png
 

tsteward

Well-Known Member
Licensed User
$res = 0 fail
and it fails to insert data.

using var_dump returns this
VarTablet.jpg


But when $id is numerical I get this and a successful insertion of data
VarPhone.jpg
 

tsteward

Well-Known Member
Licensed User
All good found the problem $id is not quoted and thus can only be a number. Enclosing it in quotes solved the problem.
 
Top