Ir ao conteúdo

Posts recomendados

Postado

estou com dificuldades de compreender como eu posso editar(update) do usuario do meu site php que esta no banco de dados(phpmyadmin),neste caso quero editar cada registro separado[tipo,nome dele ta joao,caso ele clica no botao editar e por nome de carlos,o restante permanece o mesmo.]

 

pagina de perfil:

<?php
session_start();
$nomeDoUsuario = $_SESSION["nome"];
$telefone = $_SESSION["telefone"];
?>
<!doctype html>
<html lang="en" data-bs-theme="auto">
  <head>
      <script src="../assets/js/color-modes.js">
    </script>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="Mark Otto, Jacob Thornton, and Bootstrap contributors">
    <meta name="generator" content="Hugo 0.118.2">
    <title>Perfil</title>

    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>

    <style>
    table, th,td{
      margin:20px;
      border: 1px solid black;
      border-collapse: collapse;
    }

    .circle {
  background-color: #aaa;
  border-radius: 50%;
  width: 200px;
  height: 200px;
  overflow: hidden;
  position: relative;
  float: left;
  margin:auto;
}

      .circle img {
  position: absolute;
  bottom: 0;
  width: 100%;
  text-align:center;
  display:block;
  }

  .caixa{
    height:100px;
    width:200px;
    margin:auto;
    text-align:center;
  }

    </style>

</head>
<body>

<div class="caixa">
    <div class="circle">
      <img class="img" src="download (1).png">
      
    </div>
    <?php
               echo  $_SESSION["nome"];
               ?>
<table>
<tr>
<th>Nome:</th>
</tr>
<tr>
<td><?php

echo  $_SESSION["nome"];
?></td>
<td>
<?php

print "<a href='newname.php'  class='btn btn-danger'>Editar</a>";

?>
</td>
</tr>
</table>

<table>

<tr>
<th>Telefone:</th>
</tr>
<tr>
<td><?php

echo  $_SESSION["telefone"];

?></td>
<td>
<?php

print "<a href='logout.php' class='btn btn-danger'>Editar</a>";

?></td>

</tr>
</table>

<table>
<tr>
<th>E-mail:</th>
</tr>
<tr>
<td><?php

echo  $_SESSION["login"];

?></td>

<td>
<?php
print "<a href='logout.php' class='btn btn-danger'>Editar</a>";
?>
</td>
</tr>
</table>

<table>
<tr>
<th>Senha:</th>
</tr>
<tr>
<td><?php

echo  $_SESSION["senha"];

?></td>

<td>
<?php
print "<a href='logout.php' class='btn btn-danger'>Editar</a>";
?>
</td>
</tr>
</table>

</body>
</html>

pagina newname.php:

<!doctype html>
<html lang="en" data-bs-theme="auto">
  <head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="Mark Otto, Jacob Thornton, and Bootstrap contributors">
    <meta name="generator" content="Hugo 0.118.2">
    <title>Editar</title>
    <link rel="canonical" href="https://getbootstrap.com/docs/5.3/examples/headers/">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@docsearch/css@3">

<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="sign-in.css" rel="stylesheet">

    <style>
      </style>
      <link href="headers.css" rel="stylesheet">
</head>

<body class="d-flex align-items-center py-4 bg-body-tertiary">
    <svg xmlns="http://www.w3.org/2000/svg" class="d-none">
      <symbol id="check2" viewBox="0 0 16 16">
        <path d="M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0z"></path>
      </symbol>
      <symbol id="circle-half" viewBox="0 0 16 16">
        <path d="M8 15A7 7 0 1 0 8 1v14zm0 1A8 8 0 1 1 8 0a8 8 0 0 1 0 16z"></path>
      </symbol>
      <symbol id="moon-stars-fill" viewBox="0 0 16 16">
        <path d="M6 .278a.768.768 0 0 1 .08.858 7.208 7.208 0 0 0-.878 3.46c0 4.021 3.278 7.277 7.318 7.277.527 0 1.04-.055 1.533-.16a.787.787 0 0 1 .81.316.733.733 0 0 1-.031.893A8.349 8.349 0 0 1 8.344 16C3.734 16 0 12.286 0 7.71 0 4.266 2.114 1.312 5.124.06A.752.752 0 0 1 6 .278z"></path>
        <path d="M10.794 3.148a.217.217 0 0 1 .412 0l.387 1.162c.173.518.579.924 1.097 1.097l1.162.387a.217.217 0 0 1 0 .412l-1.162.387a1.734 1.734 0 0 0-1.097 1.097l-.387 1.162a.217.217 0 0 1-.412 0l-.387-1.162A1.734 1.734 0 0 0 9.31 6.593l-1.162-.387a.217.217 0 0 1 0-.412l1.162-.387a1.734 1.734 0 0 0 1.097-1.097l.387-1.162zM13.863.099a.145.145 0 0 1 .274 0l.258.774c.115.346.386.617.732.732l.774.258a.145.145 0 0 1 0 .274l-.774.258a1.156 1.156 0 0 0-.732.732l-.258.774a.145.145 0 0 1-.274 0l-.258-.774a1.156 1.156 0 0 0-.732-.732l-.774-.258a.145.145 0 0 1 0-.274l.774-.258c.346-.115.617-.386.732-.732L13.863.1z"></path>
      </symbol>
      <symbol id="sun-fill" viewBox="0 0 16 16">
        <path d="M8 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM8 0a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2A.5.5 0 0 1 8 0zm0 13a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2A.5.5 0 0 1 8 13zm8-5a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1 0-1h2a.5.5 0 0 1 .5.5zM3 8a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1 0-1h2A.5.5 0 0 1 3 8zm10.657-5.657a.5.5 0 0 1 0 .707l-1.414 1.415a.5.5 0 1 1-.707-.708l1.414-1.414a.5.5 0 0 1 .707 0zm-9.193 9.193a.5.5 0 0 1 0 .707L3.05 13.657a.5.5 0 0 1-.707-.707l1.414-1.414a.5.5 0 0 1 .707 0zm9.193 2.121a.5.5 0 0 1-.707 0l-1.414-1.414a.5.5 0 0 1 .707-.707l1.414 1.414a.5.5 0 0 1 0 .707zM4.464 4.465a.5.5 0 0 1-.707 0L2.343 3.05a.5.5 0 1 1 .707-.707l1.414 1.414a.5.5 0 0 1 0 .708z"></path>
      </symbol>
    </svg>

  
    
<main class="form-signin w-100 m-auto">
  <form action="newnamecadastrado.php" method="post">
    <img class="mb-4" src="download.png" alt="" width="72" height="57">
    <h1 class="h3 mb-3 fw-normal">Editar</h1></img>

    <div class="form-floating">
      <input type="text" class="form-control" name="nome" id="floatingInput" placeholder="João" required>
      <label for="floatingInput">Nome:</label>
    </div>

    <div class="form-check text-start my-3">
      <input class="form-check-input" type="checkbox" value="remember-me" id="flexCheckDefault">
      <label class="form-check-label" for="flexCheckDefault">
       Permanecer conectado
      </label>
    </div>
    <button class="btn btn-primary w-100 py-2" type="submit">Efetuar edição</button>
    <p class="mt-5 mb-3 text-body-secondary">© 2025-2026</p>
  </form>
</main>
<script src="/docs/5.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>


</body>
</html>

pagina newnamecadastrado.php:

<?php

session_start();

//inclui a conexao com o banco de dados
include_once ('conexao.php');

//recebe os dados vindo do formulário
$nome = $_POST['nome'];
$id = $_SESSION['idUsuario'];

if(empty($nome)){
   echo "preencha todos os campos.";
   exit;
}else{
  $sql = "SELECT id, nome, telefone, email, senha FROM cadastros WHERE nome = '$nome'";
  if(isset($_POST['nome'])){
  $result = "UPDATE cadastros SET nome=$nome WHERE id=$id";
}
  //executa a instrução SQL de inserir na tabela
  $result = "UPDATE cadastros SET nome=$nome WHERE id=$id";
}


 
header("location: acc.php");
?>

 

Postado

Olá!
Segue sugestão de solução:
Crie uma modal para editar os dados pessoais
image.png.cf691569e2204620096b0391b68d7c89.png

E outra exclusiva para troca de senha:
image.png.bd25b106fa8a9a7de27c610a8271f20e.png

 

<div class="modal fade" id="profile" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <h1 class="modal-title fs-5" id="staticBackdropLabel">Editar</h1>
          <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
        </div>
        <div class="modal-body">
          <form id="profile-form" method="post" action="profile/save">
            <div class="row">
              <div class="col-12">
                <label>Nome:</label>
                <input type="text" class="form-control" value="<?= $nomeDoUsuario ?>" required>
              </div>
              <div class="col-md-6 mt-2">
                <label>Telefone:</label>
                <input type="tel" class="form-control" value="<?= $telefone ?>" required>
              </div>
              <div class="col-md-6 mt-2">
                <label>Email:</label>
                <input type="email" class="form-control" value="<?= $email ?>" required>
              </div>
            </div>
          </form>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
          <button type="submit" form="profile-form" class="btn btn-warning">Atualizar <i class="fa-solid fa-floppy-disk"></i></button>
        </div>
      </div>
    </div>
  </div>


 

  <!-- Modal -->
  <div class="modal fade" id="password-change" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
    <div class="modal-dialog modal-sm">
      <div class="modal-content">
        <div class="modal-header">
          <h1 class="modal-title fs-5" id="staticBackdropLabel">Trocar senha</h1>
          <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
        </div>
        <div class="modal-body">
          <form id="password-form" method="post" action="profile/new-password">
            <div class="row">
              <div class="col-12">
                <label>Senha atual:</label>
                <input type="password" class="form-control" required>
              </div>
              <div class="col-12 mt-2">
                <label>Nova senha:</label>
                <input type="password" class="form-control" required>
              </div>
              <div class="col-12 mt-2">
                <label>Confirmar nova senha:</label>
                <input type="password" class="form-control"  required>
              </div>
            </div>
          </form>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
          <button type="submit" form="password-form" class="btn btn-warning">Atualizar <i class="fa-solid fa-floppy-disk"></i></button>
        </div>
      </div>
    </div>
  </div>


 

Crie uma conta ou entre para comentar

Você precisa ser um usuário para fazer um comentário

Criar uma conta

Crie uma nova conta em nossa comunidade. É fácil!

Crie uma nova conta

Entrar

Já tem uma conta? Faça o login.

Entrar agora

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

GRÁTIS: ebook Redes Wi-Fi – 2ª Edição

EBOOK GRÁTIS!

CLIQUE AQUI E BAIXE AGORA MESMO!