B4J Question Data from onlineDB B4A B4J diff results

Discussion in 'B4J Questions' started by tsteward, Apr 13, 2015.

  1. tsteward

    tsteward Active 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.

    Code:
    ("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.
    Code:
    ("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
    Code:
    <?
    $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?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Use var_dump in your php script to compare the requests.
     
  3. tsteward

    tsteward Active 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
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Which error do you get?
     
  5. tsteward

    tsteward Active 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
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    This is the server response? Where does it come from? You are executing an INSERT command.
     
  7. tsteward

    tsteward Active 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.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice