BossBey File Manager
PHP:
8.4.18
OS:
Linux
User:
kids
Root
/
home
/
kids
/
public_html
/
app
š¤ Upload
š New File
š New Folder
Close
Editing: update.php
<?php session_start(); require_once "connection.php"; //var_dump($_POST); //var_dump($_SESSION); $mensagem = ""; if (isset($_SESSION["email_to_reset"]) && isset($_POST["id"]) && isset($_POST["origem"]) && isset($_POST["new_password"])) { $email = $_SESSION["email_to_reset"]; $id = $_POST["id"]; $origem = $_POST["origem"]; $senha = password_hash($_POST["new_password"], PASSWORD_DEFAULT); $reset = 0; $sql = "UPDATE $origem SET senha = :senha, rec_senha = :rec_senha WHERE id = :id"; $stmt = $pdo->prepare($sql); $stmt->bindParam(":id", $id); $stmt->bindParam(":senha", $senha); $stmt->bindParam(":rec_senha", $reset); if ($stmt->execute()) { session_unset(); $mensagem = "Senha definida com sucesso! Realize o login"; echo "<script> alert('$mensagem'); setTimeout(function() { window.location.href = 'login.php'; }, 500); </script>"; } else { $mensagem = "Opa! Algo deu errado. Entre em contato com o suporte."; } unset($stmt); unset($pdo); } if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["id"])) { $id = $_POST["id"]; $nome = $_POST["nome"]; $nascimento = $_POST["nascimento"]; $senha = password_hash($_POST["senha"], PASSWORD_DEFAULT); $email = $_POST["email"]; $telefone = $_POST["telefone"]; $nivelAcesso = $_POST["nivelAcesso"]; $obs = $_POST["obs"]; $postorigem = $_POST["origem"]; $sql = "UPDATE $postorigem SET nome = :nome, nascimento = :nascimento, senha = :senha, email = :email, telefone = :telefone, nivelAcesso = :nivelAcesso, obs = :obs WHERE id = :id"; $stmt = $pdo->prepare($sql); $stmt->bindParam(":id", $id); $stmt->bindParam(":nome", $nome); $stmt->bindParam(":nascimento", $nascimento); $stmt->bindParam(":senha", $senha); $stmt->bindParam(":email", $email); $stmt->bindParam(":telefone", $telefone); $stmt->bindParam(":nivelAcesso", $nivelAcesso); $stmt->bindParam(":obs", $obs); if ($stmt->execute()) { $mensagem = "UsuĆ”rio editado com sucesso!"; echo "<script> alert('$mensagem'); setTimeout(function() { window.location.href = 'inicial.php'; }, 500); </script>"; } else { $mensagem = "Opa! Algo deu errado. Entre em contato com o suporte."; } unset($stmt); unset($pdo); } ?> <!DOCTYPE html> <html lang="pt-br"> <head> <meta charset="UTF-8"> <title>Edição de usuĆ”rio no sistema</title> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"> <style> .wrapper{ width: 500px; margin: 0 auto; } </style> </head> <body> <div class="wrapper"> <div class="container-fluid"> <div class="row"> <div class="col-md-12"> <h2 class="mt-5">Editar usuĆ”rio</h2> <?php if(isset($_GET["id"]) && !empty(trim($_GET["id"]))){ $id = trim($_GET["id"]); $getorigem = trim($_GET["origem"]); $sql = "SELECT * FROM $getorigem WHERE id = :id"; if($stmt = $pdo->prepare($sql)){ $stmt->bindParam(":id", $param_id); $param_id = $id; if($stmt->execute()){ if($stmt->rowCount() == 1){ $row = $stmt->fetch(PDO::FETCH_ASSOC); $nome = $row["nome"]; $nascimento = $row["nascimento"]; $senha = $row["senha"]; $email = $row["email"]; $telefone = $row["telefone"]; $nivelAcesso = $row["nivelAcesso"]; $obs = $row["obs"]; } else{ header("location: error.php"); exit(); } } else{ echo "Oops! Algo deu errado. Por favor, tente novamente mais tarde."; } } unset($stmt); } else{ header("location: error.php"); exit(); } ?> <form action="update.php" method="post"> <input type="hidden" name="id" value="<?php echo $id; ?>"> <input type="hidden" name="origem" value="<?php echo $getorigem; ?>"> <div class="form-group"> <label>Nome</label> <input type="text" name="nome" class="form-control" <?php if($_SESSION["nivelAcesso"]=="prof"){echo 'readonly';}?>value="<?php echo $nome; ?>"> </div> <div class="form-group"> <label>Nascimento</label> <input type="text" name="nascimento" class="form-control" <?php if ($_SESSION["nivelAcesso"] == "prof") { echo 'readonly'; } ?> value="<?php echo $nascimento; ?>" placeholder="dd/mm/aaaa" pattern="\d{2}/\d{2}/\d{4}" required> </div> <div class="form-group"> <label>Senha</label> <input type="password" name="senha" class="form-control" <?php if($_SESSION["nivelAcesso"]=="prof"){echo 'readonly';}?> value="<?php echo $senha; ?>"> </div> <div class="form-group"> <label>Email</label> <input type="email" name="email" class="form-control" <?php if($_SESSION["nivelAcesso"]=="prof"){echo 'readonly';}?> value="<?php echo $email; ?>"> </div> <div class="form-group"> <label>Telefone</label> <input type="text" name="telefone" class="form-control" <?php if($_SESSION["nivelAcesso"]=="prof"){echo 'readonly';}?>value="<?php echo $telefone; ?>"> </div> <div class="form-group" readonly> <label>NĆvel de Acesso</label> <input type="text" name="nivelAcesso" class="form-control" readonly value="<?php echo $nivelAcesso; ?>"> </div> <div class="form-group"> <label>ObservaƧƵes</label> <textarea name="obs" class="form-control" rows="5"><?php echo $obs; ?></textarea> </div> <input type="submit" class="btn btn-primary" value="Salvar"> <a href="inicial.php" class="btn btn-secondary ml-2">Cancelar</a> </form> </div> </div> </div> </div> <script> document.addEventListener('DOMContentLoaded', function () { const inputNascimento = document.querySelector('input[name="nascimento"]'); inputNascimento.addEventListener('input', function () { const inputValue = inputNascimento.value; // Verificar se o comprimento Ć© 2 ou 5 if (inputValue.length === 2 || inputValue.length === 5) { // Adicionar uma barra ("/") se o comprimento for 2 ou 5 inputNascimento.value += '/'; } }); }); </script> </body> </html>
Save
Cancel