I want to get the details of the user who has logged in. I am getting null or no value in the alert dialog (var - name)
I am new to everything so I am sorry if the question is not worth it, I have tried finding the solutions but no luck yet so please help.
if (type.equals("linkuser")) {
try {
URL url = new URL(Link_url);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
OutputStream outputStream = httpURLConnection.getOutputStream();
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
String post_data = URLEncoder.encode("user", "UTF-8") + "=" + URLEncoder.encode(user, "UTF-8");
bufferedWriter.write(post_data);
bufferedWriter.flush();
bufferedWriter.close();
outputStream.close();
InputStream inputStream = httpURLConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"));
String result = "";
String line = "";
while ((line = bufferedReader.readLine()) != null) {
result += line;
}
bufferedReader.close();
inputStream.close();
httpURLConnection.disconnect();
return result;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Your php query is wrong
Initialize array first Note that $result is not your array
$menus= array();
while($row = mysqli_fetch_array($result )){
array_push($menus,
array('name'=>$row[0],
'ign'=>$row[1],
'email'=>$row[2]
));
}
mysqli_close($con);
echo json_encode(array("menu"=>$menus));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.