Não está a guardar as alterações no mysql

0 respostas
mysqlphp
J

Estou com um problema a armazenar no mysql os dados. O que acontece é que depois de adicionar uma pessoa é possível editar os dados. Quando adiciono a pessoa funciona tudo direitinho mas quando quero editar já não grava as alterações. Aqui fica o código:

<?php
session_start();

error_reporting(0);

include(includes/config.php);

if(strlen($_SESSION[alogin])==0)

{

header(‘location:index.php);

}

else{

if(isset($_POST[update]))

{

$did=intval($_GET[deptid]);

$nomeutente=$_POST[NomeUtente];

$nomeprof=$_POST[NomeProf];

$nrutente=$_POST[NrUtente];
$sql=update tblutentes set NomeUtente=:nomeutente, NomeProf=:nomeprof, NrUtente=:nrutente, PessoaRef=:pessoaref where id=:did;

$query = $dbh->prepare($sql);

$query->bindParam(:nomeutente,$nomeutente,PDO::PARAM_STR);

$query->bindParam(:nomeprof,$nomeprof,PDO::PARAM_STR);

$query->bindParam(:nrutente,$nrutente,PDO::PARAM_STR);

$query->bindParam(:pessoaref,$pessoaref,PDO::PARAM_STR);

$query->bindParam(:did,$did,PDO::PARAM_STR);

$query->execute();

$msg=Informações Alteradas com Sucesso!;

}?>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>


<body>

 <nav>
      <div class="nav-wrapper">
          <a href="paginainicial.php"><img src="img/profile-image.png" alt="" class="circle responsive-img"></a>
      </div>
<div class="container">
        
         <div class="row">
            <form class="col s12" method="POST">
               <?php if($error){?><div class="errorWrap"><strong>ERRO</strong>:<?php echo htmlentities($error); ?> </div><?php } 
            else if($msg){?><div class="succWrap"><strong>SUCESSO</strong> : <?php echo htmlentities($msg); ?> </div><?php }?>
<?php $did=intval($_GET['deptid']); $sql = "SELECT * from tblutentes WHERE id=:did"; $query = $dbh -> prepare($sql); $query->bindParam(':did',$did,PDO::PARAM_STR); $query->execute(); $results=$query->fetchAll(PDO::FETCH_OBJ); $cnt=1; if($query->rowCount() > 0) { foreach($results as $result) { ?>
<div class="row">
                <div class="input-field col s6">
                  <i class="material-icons prefix">account_circle</i>
                  <input id="NomeUtente" type="text"  class="validate" autocomplete="off" value="<?php echo htmlentities($result->NomeUtente);?>" name="NomeUtente" required>
                  <label for="nomeutente" class="active">Nome Completo</label>
                </div>
                <div class="input-field col s6">
                  <i class="material-icons prefix">person_outline</i>
                  <input id="NrUtente" type="text"  class="validate" autocomplete="off" value="<?php echo htmlentities($result->NrUtente);?>" name="NrUtente" required>
                  <label for="nrutente" class="active">Número de Processo</label>
                </div>
                <div class="input-field col s6">
                  <i class="material-icons prefix">account_circle</i>
                  <input id="Responsavel" type="text"  class="validate" autocomplete="off" value="<?php echo htmlentities($result->Responsavel);?>" name="Responsavel" required>
                  <label for="responsavel" class="active">Responsável Legal</label>
                </div>
                <div class="input-field col s6">
                  <i class="material-icons prefix">account_circle</i>
                  <input id="PessoaRef" type="text"  class="validate" autocomplete="off" value="<?php echo htmlentities($result->PessoaRef);?>" name="PessoaRef" required>
                  <label for="pessoaref" class="active">Pessoa de Referência</label>
                </div>
<?php }} ?>
<button class="btn #ff7043 deep-orange lighten-1 right" type="submit" name="update">Atualizar
                  <i class="material-icons right">send</i>
                </button>

                <a class="btn #ff7043 deep-orange lighten-1 left" href="utentes.php"><i class="material-icons left">exit_to_app</i>Retroceder</a>
         
              </div>
            </form>
          </div>

      
                          
    </div>

  <!--Import jQuery before materialize.js-->
  <script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
  <script type="text/javascript" src="js/materialize.min.js"></script>
</body>
<?php }?>
Criado 30 de maio de 2018
Respostas 0
Participantes 1