I am new to Android Programming.I am trying to build an Android Project which is connected to an online MySQL Server using PHP to pass the data from Android device to the online Server.I have two tables one of which contains the login details of the employee i.e.EMPLOYEE_DATA, and the 2nd table contains the respective employee details i.e.EMPLOYEE_DETAILS.
So, I have 2 PHP files : the 1st PHP script is for the Login of the employee which runs when the employee clicks on the Login Button.This script needs to get the username of the employee which is logged in and pass it to the second PHP file.The 2nd PHP script is used for inserting the details of the respective employees. Now I need to pass the username from the 1st PHP scriptto the 2nd PHP script and insert that username to the "USERNAME" column of the table "EMPLOYEE_DETAILS". Can anyone please suggest how to proceed. I have tried using $_SESSIONS but am not getting the desired result. I have been stuck with this for a long time. Any help would be appreciated.
Edit 1 :
Login.php
<?php
$_SESSION['user_mobile'] = $_POST["mobile_num"];
$_SESSION['user_pass'] = $_POST["password"];
require "conn.php";
$user_mobile='';
$user_pass='';
$user_mobile = $_SESSION['user_mobile'];
$user_pass = $_SESSION['user_pass'];
$mysql_qry = "select * from employee_data where mobile like '$user_mobile' and password like '$user_pass';";
$result = mysqli_query($conn,$mysql_qry);
if(mysqli_num_rows($result) > 0 ) {
$row = mysqli_fetch_assoc($result);
$_POST['user'] = $name;
$name= $row["name"];
echo "Login successful.<br /> Welcome " ;
echo $name;
$insertName = "INSERT INTO employee_details(name) VALUES ('$name');";
$resultName = mysqli_query($conn,$insertName);
$shift = "SELECT CASE WHEN CURTIME() < 7 THEN 'Morning'
WHEN CURTIME() < 12 THEN 'Afternoon'
WHEN CURTIME() <17 THEN 'Evening'
ELSE 'Night'
END;";
$insertShift = "insert into employee_details(shift) values ('$shift');";
$resultShift = mysqli_query($conn,$insertShift);
}
else{
echo "Login failed.";
}
?>
I want to pass the $name variable to another PHP Script which will be used to insert the details of the user which is currently logged in.So, the username of the Employee will come from the $name variable and the other details will be the input from the Android device.
Edit 2:
Insert.php
<?php
require "conn.php";
include "login.php";
echo $_POST['user'];
$enquiry = $_POST["enquiry"];
$retail = $_POST["retail"];
$collection = $_POST["collection"];
$booking = $_POST["booking"];
$evaluation = $_POST["evaluation"];
$test_drive = $_POST["test_drive"];
$home_visit = $_POST["home_visit"];
date_default_timezone_set('Asia/Kolkata');
$IST = date('d-m-Y H:i');
$mysql_qry1 = "INSERT INTO employee_details(enquiry,retail,
collection,booking, evaluation, test_drive, home_visit, date, time) values ('$enquiry','$retail','$collection','$booking','$evaluation','$test_drive',
'$home_visit',CURDATE(),CURTIME());";
$shift = "SELECT TIME(CURRENT_TIME),
CASE WHEN TIME(CURRENT_TIME) BETWEEN '01:00:00' AND '07:00:00' THEN 'Morning'
WHEN TIME(CURRENT_TIME) BETWEEN '08:00:00' AND '13:00:00' THEN 'Afternoon'
WHEN TIME(CURRENT_TIME) BETWEEN '13:00:00' AND '18:00:00' THEN 'Evening'
END;";
$mysql_qry2 = "INSERT INTO employee_details(shift) values ('$shift');";
$ins = mysqli_query($conn,$mysql_qry2);
if($conn->query($mysql_qry1) === TRUE)
echo "Your details has been successfully inserted.";
else
echo "Error: " .$mysql_qry1. "<br>" . $conn->error;
$conn->close();
?>
I want to pass the $name variable from "Login.php" to "Insert.php" and insert into the "USERNAME" column in employee_details.
Welcome " .$name;` its a response that android gets after calling login.php ...store this response in some variable of shared preferance... split name from it,,,, and post this variable when user click the submit – Abhishek Singh Jan 31 '17 at 07:20
Welcome " .$name; The whole string is passed as a parameter in onPostExecute() method.Can you please tell me how to split the $name. I am not able to figure out how to get only the $name variable from the PHP script and use it in the Shared Peference. – Pranami Jan 31 '17 at 07:35
Welcome ______" .$name;` then in android String[] str=youresponse.split("_____");..... name were contained in str[1].... – Abhishek Singh Jan 31 '17 at 09:14