<?php
#usersEditar.php?alterar
if(!isset($_GET['alterar'])){
// pesquisar
require_once("connection.php");
$id=$_GET['idUser'];
$table="v1_users";
$sql="SELECT * FROM $table WHERE idUser=$id";
$queryUsers=mysqli_query($connect, $sql) or die ($sql);
$fetchUsers=mysqli_fetch_assoc($queryUsers);
$table="privilegios";
$sql="SELECT * FROM $table";
$queryPriv=mysqli_query($connect, $sql) or die ($sql);
$fetchPriv=mysqli_fetch_assoc($queryPriv);
}
if(isset($_GET['alterar'])){
// alterar
$id=$_GET['idUser'];
$idPrivilegio=$_GET['idPrivilegio'];
$nome=addslashes($_GET['nome']);
$apelido=addslashes($_GET['apelido']);
$table="users";
$sql="UPDATE $table SET nome='$nome', apelido='$apelido', idPrivilegio=$idPrivilegio WHERE id=$id";
require_once("connection.php");
mysqli_query($connect, $sql) or die($sql);
header("Location:usersListar.php");
}
?>
<!DOCTYPE html>
<html lang="pt">
<head>
<meta charset="UTF-8">
<title>Editar utilizadores</title>
</head>
<body>
<h1>Editar os dados do utilizador</h1>
<form>
<input type="text" name="nome" required placeholder="Primeiro nome:" value="<?php echo $fetchUsers['nome'];?>">
<br>
<input type="text" name="apelido" required placeholder="Apelido:" value="<?php echo $fetchUsers['apelido'];?>">
<br>
<input type="text" name="username" value="<?php echo $fetchUsers['username'];?>" readonly>
<br>
<input type="text" name="idUser" value="<?php echo $fetchUsers['idUser'];?>" readonly>
<br>
<select name="idPrivilegio">
<option value="<?php echo $fetchUsers['idPrivilegio'];?>">
<?php echo $fetchUsers['privilegio'];?>
</option>
<?php do {?>
<?php if($fetchUsers['idPrivilegio']!=$fetchPriv['id']){?>
<option value="<?php echo $fetchPriv['id'];?>">
<?php echo $fetchPriv['privilegio'];?>
</option>
<?php }?>
<?php } while($fetchPriv=mysqli_fetch_assoc($queryPriv));?>
</select>
<input type="submit" name="alterar">
</form>
</body>
</html>
Sem comentários:
Enviar um comentário