View sourcecode

The following files exists in this folder. Click to view.

changeActiveUser.php

26 lines UTF-8 Unix (LF)
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
<?php
require_once('check_login.php');        # Kollar om vi är inloggade
require_once('database_connection.php'); # Läs in databasuppkopplingen

$userId trim($_GET['userId']);        # hämta userId från URL

# Hämta värde för active för vår user
$sql "SELECT active FROM user1 WHERE userId = :userId;";
$stm $pdo->prepare($sql);
$stm->execute(array('userId' => $userId));

# fetch() eftersom vi hämtar en post
$res $stm->fetch(PDO::FETCH_ASSOC);

# Använd shorthanded if för att kolla om $res['active'] är 1,
# om så är fallet sätt $active till 0, annars till 1
$active $res['active'] == 1;

# Gör anropet till databasen
$sql "UPDATE user1 SET active = :active WHERE userId = :userId";
$stm $pdo->prepare($sql);
$stm->execute(array('active' => $active'userId' => $userId));

# skicka till admin med ett meddelande
header("location: admin.php?mess=Användaren med id: $userId har uppdaterats.");