Android Question help with php

tufanv

Expert
Licensed User
Longtime User
Hello

I need help for a basic php command because i don't understand php well. Currectly in my php code i have

B4X:
    case "1":

        $cihaz = clean($_GET["girdi3"]);
        $uname = clean($_GET["girdi1"]);
        $passw = clean($_GET["girdi2"]);
       
        $q = "SELECT username FROM tblusers WHERE username = '".$uname."'";
        $r = mysql_query($q);
       
        if ( mysql_num_rows($r) > 0 )
        {
            print json_encode('This username already exists');
        } else {
            $q = mysql_query("INSERT INTO tblusers (username,password,cihazid) VALUES ('$uname',  '$passw', '$cihaz')");
            print json_encode("Inserted");
        }
        break;

i send the parameters from my app as girdi1,girdi2 and girdi3. This works well for a registeration process. What I want to add is , I have a different table called tblblocked . I also want to check if the "girdi3" exists in the tblblocked. ( girdi 3 is the device id , so if the device id is in block list i dont want to accept the registration.) tblblocked has only 1 coloums and it is deviceid. So basicly i have to add after -username already exist check - if girdi3 is in the tblblocked under coloumn deviceid. Can you help me add it to code.

TY
 

sorex

Expert
Licensed User
Longtime User
next time put echo mysql_error(); right after the query command and it will tell you what's wrong.
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
I have another question regarding php. It must be quitesimple but i dont know how to do it
the part of my code :
B4X:
    $q = "SELECT cihazid,username,cesit,nesne FROM tblusers WHERE cihazid = '".$cihaz."'";
                $r = mysql_query($q);
                $a = mysql_fetch_assoc($r);
                if ( mysql_num_rows($r) > 0 )
                {
                    print json_encode("$a['username']);
                } else {

with this, i can successfuly get the username from db and put it into label1 in my app with retrieved json. I also want to put the other values : cesit,nesne,cihazid into label2,3,4 . Icant put them all into json as single line because later in the app i cant extract them. How can i get them as a map or list for example so i can retrieve the field i like in my app ?

TY
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
you can pull in all records and feed that to the encoder.

B4X:
echo json_encode($a);
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…