Android Question Error Connect Android to MySQL Database Query Variable Get Empty

Ajws

Member
Licensed User
mysql.php code:
<?php

$databasehost = "localhost";
$databasename = "asc202304";
$databaseusername ="root";
$databasepassword = "xxxxxxxx";

$con = mysqli_connect($databasehost,$databaseusername,$databasepassword, $databasename) or die(mysqli_error($con));
mysqli_set_charset ($con , "utf8");
$query = file_get_contents("php://input");
$sth = mysqli_query($con, "SET SESSION GROUP_CONCAT_MAX_LEN =1000000");
 //you can set the query by adding the query parameter  For ex: http://127.0.0.1/test.aspx?query=select * from table1
 
$sth = mysqli_query($con, $query);
if (mysqli_errno($con)) {
   header("HTTP/1.1 500 Internal Server Error");
   echo $query.'\n';
   echo mysqli_error($con);
}
else
{
   $rows = array();
   while($r = mysqli_fetch_assoc($sth)) {
     $rows[] = $r;
   }
   $res = json_encode($rows);
    echo $res;
    mysqli_free_result($sth);
}
mysqli_close($con);
?>

Hai All Please Help
link : https://www.b4x.com/android/forum/threads/connect-android-to-mysql-database-tutorial.8339/#content

i cannot get result of query, so i test from browser like this : http://localhost/mysql.php?query=select * from tbltrans

and result is
1682873058802.png

why ? variable query is empty.
i'm not familiar with php.

please help
 

aeric

Expert
Licensed User
Longtime User
Do you see %20 in the address bar? You should not pass spaces or if you do, you need to use URL decode to read. However it is still not right to pass your SQL command as query parameter.

Edit: The example is using POST. You can't use job.Download or GET (web browser).
 
Upvote 0
Top