select table rows and edit user
This commit is contained in:
@@ -191,7 +191,7 @@ function write_team($con, $team_name, $fire_department) {
|
||||
|
||||
function get_users($con) {
|
||||
try {
|
||||
$stmt = $con->prepare("SELECT user_name, user_group, s_id FROM users");
|
||||
$stmt = $con->prepare("SELECT id, user_name, user_group, s_id FROM users");
|
||||
$stmt->execute();
|
||||
$stmt->setFetchMode(PDO::FETCH_ASSOC);
|
||||
return $stmt;
|
||||
@@ -200,6 +200,17 @@ function get_users($con) {
|
||||
}
|
||||
}
|
||||
|
||||
function get_user($con, $id) {
|
||||
try {
|
||||
$stmt = $con->prepare("SELECT * FROM users WHERE id = :id");
|
||||
$stmt->execute(['id' => $id]);
|
||||
$stmt->setFetchMode(PDO::FETCH_ASSOC);
|
||||
return $stmt;
|
||||
} catch(PDOException $e) {
|
||||
handle_pdo_exception($e);
|
||||
}
|
||||
}
|
||||
|
||||
function write_user($con, $user_name, $user_id, $phash, $salt, $user_group, $s_id) {
|
||||
try {
|
||||
$stmt = $con->prepare("INSERT INTO users (user_id, password, user_name, salt, user_group, s_id) VALUES (?, ?, ?, ?, ?, ?)");
|
||||
@@ -213,4 +224,38 @@ function write_user($con, $user_name, $user_id, $phash, $salt, $user_group, $s_i
|
||||
} catch(PDOException $e) {
|
||||
handle_pdo_exception($e);
|
||||
}
|
||||
}
|
||||
|
||||
function change_user_name($con, $id, $user_name) {
|
||||
try {
|
||||
$stmt = $con->prepare("UPDATE users SET user_name = ? WHERE id= ?");
|
||||
$stmt->bindParam(1, $user_name, PDO::PARAM_STR);
|
||||
$stmt->bindParam(2, $id, PDO::PARAM_STR);
|
||||
$stmt->execute();
|
||||
} catch(PDOExeption $e) {
|
||||
handle_pdo_exception($e);
|
||||
}
|
||||
}
|
||||
|
||||
function change_user_group($con, $id, $user_group, $s_id) {
|
||||
try {
|
||||
$stmt = $con->prepare("UPDATE users SET user_group = ?, s_id = ? WHERE id= ?");
|
||||
$stmt->bindParam(1, $user_group, PDO::PARAM_STR);
|
||||
$stmt->bindParam(2, $s_id, PDO::PARAM_INT);
|
||||
$stmt->bindParam(3, $id, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
} catch(PDOExeption $e) {
|
||||
handle_pdo_exception($e);
|
||||
}
|
||||
}
|
||||
|
||||
function change_password($con, $id, $password) {
|
||||
try {
|
||||
$stmt = $con->prepare("UPDATE users SET password = ? WHERE id= ?");
|
||||
$stmt->bindParam(1, $password, PDO::PARAM_STR);
|
||||
$stmt->bindParam(2, $id, PDO::PARAM_STR);
|
||||
$stmt->execute();
|
||||
} catch(PDOExeption $e) {
|
||||
handle_pdo_exception($e);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user