Advertisement
Guest User

AJUDA PHP UPDATE FORMULARIO WEB

a guest
Nov 24th, 2016
119
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3.     require_once 'db/conexa.php';
  4.  
  5.     ini_set('display_errors', true);
  6.     error_reporting(E_ALL);
  7.  
  8.     # INICIO - ATUALIZAR USUARIO
  9.  
  10.     if(isset($_POST['atualizar'])){
  11.         $id = (int)$_GET['id'];
  12.         $nome = (string)$_POST['nome'];
  13.         $senha = (string)$_POST['senha'];
  14.         $email = (string)$_POST['email'];
  15.  
  16.        
  17.  
  18.         $sqlUpdate = 'UPDATE usuarios SET nome = :nome, senha = :senha, email = :email where id = :id';
  19.  
  20.         try {
  21.             $update = $db->prepare($sqlUpdate);
  22.             $update->bindValue('id', $id, PDO::PARAM_INT);
  23.             $update->bindValue('nome', $nome, PDO::PARAM_STR);
  24.             $update->bindValue('senha', $senha, PDO::PARAM_STR);
  25.             $update->bindValue('email', $email, PDO::PARAM_STR);
  26.  
  27.             if($update->execute()){
  28.                 header('Location: http://localhost:8080/PHP/Wood/home.php');
  29.             }
  30.         } catch (Exception $e) {
  31.             echo 'Erro ao atualizar'. $e->getMessage();;
  32.         }
  33.     }
  34.  
  35.     #FIM - ATUALIZAR USUARIO
  36.  
  37.     # INICIO - PEGAR USUARIO
  38.    
  39.     $id = (int)$_GET['id'];
  40.  
  41.     $sql = 'SELECT * FROM usuarios where id = :id';
  42.     try {
  43.         $select = $db->prepare($sql);
  44.         $select->bindValue(':id', $id, PDO::PARAM_INT);
  45.         $select->execute();
  46.  
  47.     }
  48.     catch (Exception $e) {
  49.         echo $e->getMessage();
  50.     }
  51.  
  52.     $result = $select->fetch(PDO::FETCH_OBJ);
  53.     # FIM - ATUALIZAR USUARIO
  54. ?>
  55.  
  56. <!DOCTYPE html>
  57. <html>
  58. <head>
  59.     <title>Hoo</title>
  60.  
  61.      <!-- Compiled and minified CSS -->
  62.   <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.8/css/materialize.min.css">
  63.  
  64.   <!-- Compiled and minified JavaScript -->
  65.   <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.8/js/materialize.min.js"></script>
  66.            
  67. </head>
  68. <body>
  69.      <div class="row">
  70.     <form class="col s12" method="POST">
  71.       <div class="row">
  72.         <div class="input-field col s6">
  73.           <input type="text" name="nome" class="validate" value="<?php echo $result->nome; ?>">
  74.           <label></label>
  75.         </div>
  76.       </div>
  77.       </div>
  78.       <div class="row">
  79.         <div class="input-field col s6">
  80.           <input name="senha" type="password" class="validate" value="<?php echo $result->senha ?>">
  81.           <label></label>
  82.         </div>
  83.       </div>
  84.       <div class="row">
  85.         <div class="input-field col s6">
  86.           <input name="email" type="email" class="validate" value="<?php echo $result->email ?>">
  87.           <label></label>
  88.           <center><button class="btn waves-effect waves-light" type="submit" name="'atualizar'">Atualizar
  89.     <i class="material-icons right"></i></center>
  90.   </button>
  91.         </div>
  92.       </div>
  93.         </div>
  94.       </div>
  95.     </form>
  96.   </div>   
  97. </body>
  98. </html>
Advertisement
RAW Paste Data Copied
Advertisement