// if user click Login button
if(isset($_POST['btnLogin'])){
// get username and password
$username = $_POST['username'];
$password = $_POST['password'];
// set time for session timeout
$currentTime = time() + 25200;
$expired = 3600;
// create array variable to handle error
$error = array();
// check whether $username is empty or not
if(empty($username)){
$error['username'] = "*Username should be filled.";
}
// check whether $password is empty or not
if(empty($password)){
$error['password'] = "*Password should be filled.";
}
// if username and password is not empty, check in database
if(!empty($username) && !empty($password)){
// change username to lowercase
$username = strtolower($username);
//encript password to sha256
$password = hash('sha256',$username.$password);
// get data from user table
$sql_query = "SELECT ID, Role
FROM tbl_user
WHERE username = ? AND password = ?";
$stmt = $connect->stmt_init();
if($stmt->prepare($sql_query)) {
// Bind your variables to replace the ?s
$stmt->bind_param('ss', $username, $password);
// Execute query
$stmt->execute();
/* store result */
$stmt->store_result();
$stmt->bind_result($ID, $Role);
$num = $stmt->num_rows;
// Close statement object
$stmt->close();
if($num == 1){
$_SESSION['user'] = $username;
//$_SESSION['ID'] = $ID;
//$_SESSION['Role'] = $Role;
$_SESSION['id'] = $user['ID'];
$_SESSION['role'] = $user['Role'];
$_SESSION['timeout'] = $currentTime + $expired;
header("location: dashboard.php");
}else{
$error['failed'] = "Invalid Username or Password!";
}
}
}
}
private EditText Input1;
private TextView Porci2;
private TextView Porciya;
private String defaultPorciValue;
public void MyFunc(View view){
//
if(defaultPorciValue==null){
defaultPorciValue = Porci2.getText().toString().trim();
}
//
String inputStr = Input1.getText().toString().trim();
//
String porciyaStr = defaultPorciValue;
//
if(inputStr.equals("") || porciyaStr.equals("")) return;
int input1 = Integer.parseInt(inputStr);
int porci2 = Integer.parseInt(porciyaStr);
String res = String.valueOf(input1 * porci2 / 100);
Porciya.setText(res);
}
Операнд должен содержать 1 колонок