-
Notifications
You must be signed in to change notification settings - Fork 1
/
process_username.php
53 lines (45 loc) · 1.48 KB
/
process_username.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
// Start a session
session_start();
// Check if the username is provided in the POST data
if(isset($_POST['username'])) {
// Fetch the username from the POST data
$username = $_POST['username'];
// Database connection parameters
$serverName = "localhost";
$userNameDb = "root";
$password = "";
$dbName = "databaseinventory";
// Create a new database connection
$conn = new mysqli($serverName, $userNameDb, $password, $dbName);
// Check if the connection was successful
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Prepare and execute the query to fetch the full name based on the username
$queryNama = "SELECT nama_lengkap, role FROM user_account WHERE username = ?";
$stmt = $conn->prepare($queryNama);
$stmt->bind_param("s", $username);
$stmt->execute();
$stmt->bind_result($nama, $role);
$stmt->fetch();
$stmt->close();
if ($nama) {
// Save the full name in a session variable
$_SESSION['username'] = $username;
$_SESSION['namaLengkap'] = $nama;
$_SESSION['role'] = $role;
$userData = array(
'username' => $username,
'namaLengkap' => $nama,
'role' => $role,
);
// Return the user data as JSON
echo json_encode($userData);
} else {
echo "Error: Full name not found for the provided username.";
}
} else {
echo "Error: Username not provided.";
}
?>