当我在我的Android应用程序中测试时,PHP会话变量没有设置

I have tried to echo out the variable in the browser and it appears to be showing. so i would assume that the issue is in the java code, but i'm just not experienced enough to know where or what.

I have tried setting the httpconnection to public static like a similar thread suggested but was a no go.

login php and session set

  <?php
  session_start();
  include ("conn.php");

  $username = $_POST["user_name"];
  $pass = $_POST["password"];

   $qry = "select * from user where phone like '$username' and pass like 
   '$pass';";

  $result = mysqli_query($conn, $qry) or die (mysqli_error($conn));

 if (mysqli_num_rows($result) > 0) {

 while($row = mysqli_fetch_assoc($result)) {
        $uid = $row['id'];

        $_SESSION['user'] = $uid;

    echo "loginCom";
   }
?>

insert php and session target code

<?php
session_start();
include ("conn.php");

$userid = $_SESSION['user'];

$validationquery = "Select * from user where id like '$userid'";

$validationresult = mysqli_query($conn,$validationquery) or die (mysqli_error($conn));

if (mysqli_num_rows($validationresult) > 0 ) {

$flocal = $_POST["fromLocality"];
$tlocal = $_POST["toLocality"];
$flat = $_POST["fromLat"];
$flng = $_POST["fromLng"];
$tlat = $_POST["toLat"];
$tlng = $_POST["toLng"];
$timestamp = $_POST["dateTime"];
$driverid = "1";

$query = "INSERT INTO bookinginfo 
(fromlocality,tolocality,fromlat,fromlng,tolat,tolng, timestamp ,userid, 
driverid) values 
('$flocal','$tlocal','$flat','$flng','$tlat','$tlng',
'$timestamp','$uid','$driverid');";

$result = mysqli_query($conn, $query); 


echo "successfully booked";

} else {
echo "failed" .mysqli_error();
}

?>

android code for connecting to server and results

public static HttpURLConnection httpURLConnection = null;

 @Override
    protected String doInBackground(String... params) {
        String type = params[0];
        String loginUrl = "http://178.128.166.68/login.php";
        String regUrl = "http://178.128.166.68/register.php";
        String sendBookingUrl = "http://178.128.166.68/insertBooking.php";
        if (type.equals("login")) {
            try {
                String user_name = params[1];
                String password = params[2];
                URL url = new URL(loginUrl);
                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_name")+"="+ URLEncoder.encode(user_name, "UTF-8") +"&"
                        +URLEncoder.encode("password","UTF-8")+"="+URLEncoder.encode(password,"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();
                return result;

            } catch (MalformedURLException e) {
                e.printStackTrace();

            }  catch (IOException e) {
                e.printStackTrace();
            }
@Override
protected void onPostExecute(String result) {
 if (result.contentEquals("successfully booked")){
        alertDialog.setMessage("booking successful");
        alertDialog.show();
    } else {
            alertDialog.setMessage(result);
            alertDialog.show();
    }