iOS Question MySQL Database 403 Error

Mashiane

Expert
Licensed User
Hi

I need some help please... I used the B4A source to try and port it over to b4i to access the database.
This is my select.php code sitting on the server with permissions set...

B4X:
<?

$databasehost = "xxx";
$databasename = "xxx";
$databaseusername ="xxxx";
$databasepassword = "xxx";

$con = mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());
mysql_select_db($databasename) or die(mysql_error());
mysql_query("SET CHARACTER SET utf8");
$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);
}
?>

Then I run this method within my code to return a result of a select statement..

B4X:
Sub ExecuteRemoteQuery(Query As String, JobName As String)
    Dim job As HttpJob
    job.Initialize(JobName, Me)
    job.PostString("http://...select.php", Query)
End Sub

And in my job done code...
B4X:
Sub JobDone (Job As HttpJob)
    b4iMash.HideProgress
    If Job.Success = True Then
        Select Job.JobName
        Case "CheckUser"
            ' check if user exists using email address
            Log(Job.GetString)
            Dim lUsers As List = b4iMash.Json2List(Job.GetString)
            Dim eUser As Map
            Dim uTot As Int
            Dim uCnt As Int
            uTot = lUsers.Size - 1
            For uCnt = 0 To uTot
                ' get the user map
                eUser = lUsers.Get(uCnt)
                Log(eUser)
                'Dim tl As TwoLines
                'tl.First = m.Get("id")
                'tl.Second = m.Get("name")
                'ListView1.AddTwoLines2(tl.First, tl.Second, tl)
            Next
        End Select
    Else
        Msgbox(Job.ErrorMessage, "Error")
    End If
    Job.Release
End Sub

However in all my instances I get a 403 error all the time.. How can I solve this? I understand it can be my server settings perhaps, I'm not sure. Can someone advise please?
 

JanPRO

Well-Known Member
Licensed User
Hi,

first of all mysql_connect is outdated, it's better to use mysqli. The 403 error means that you have no permissons to access, what do you mean with
with permissions set
?

Off-Topic:
Be also sure your MySQL user is read only, because everybody could modify your database when he/she execute a query with select.php.
 
Upvote 0

Mashiane

Expert
Licensed User
Hi,

first of all mysql_connect is outdated, it's better to use mysqli. The 403 error means that you have no permissons to access, what do you mean with
?

Off-Topic:
Be also sure your MySQL user is read only, because everybody could modify your database when he/she execute a query with select.php.

I mean file permissions. Are there examples of mysqli that I can look at?
 
Upvote 0

Mashiane

Expert
Licensed User
Yes: http://php.net/manual/en/book.mysqli.php

Do you set the permisson with a .htaccess file, or?
Can you post the content of it?
Thanks, will check the manual. I'm using this inside b4i with the PostString of httpJob to pass a select query to it. When I open the query on Chrome it returns a /nQuery was empty, the strange thing is my b4a app works fine but used the MSMySqL library and not php with that.
 
Upvote 0

sorex

Expert
Licensed User
Don't send queries over the net and use the combination of command keywords (like ?op=getuser&id=666 or via post) and a switch on the PHP side.
 
Upvote 0

Mashiane

Expert
Licensed User
Don't send queries over the net and use the combination of command keywords (like ?op=getuser&id=666 or via post) and a switch on the PHP side.
Thanks, I eventually did that and everything is working. The .PostString method however results in a permissions issue being raised but when I use .Download, everything is fine. Ta!
 
Upvote 0

sorex

Expert
Licensed User
must be this line that's causing issues then

B4X:
$query = file_get_contents("php://input");

use $_POST("your variable name") instead when using poststring.
 
Upvote 0
Top