Guest User

exibe.php

a guest
Feb 15th, 2011
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.41 KB | None | 0 0
  1. <?php
  2. $conecta = mysql_connect('localhost','root','') or die(mysql_error());
  3. $db = mysql_select_db('cadastro') or die(mysql_error());
  4. ?>
  5. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  6. <html xmlns="http://www.w3.org/1999/xhtml">
  7. <head>
  8. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  9. <title>Exibir Usuarios</title>
  10. <link href="css/estilo.css" rel="stylesheet" type="text/css" />
  11. </head>
  12.  
  13. <body>
  14. <?php if(isset($_POST['acao']) && $_POST['acao'] == 'apagar'){
  15.     $iduser = $_POST['id'];
  16.     $del_imgs = mysql_query("SELECT * FROM usuarios WHERE id = '$iduser'");
  17.     while($lndel = mysql_fetch_array($del_imgs)){
  18.         $file = 'imagens';
  19.         $foto = $lndel['foto'];
  20.         unlink($file.'/'.$foto);
  21.     }
  22.     $deleta = mysql_query("DELETE FROM usuarios WHERE id = '$iduser'");
  23.     if($deleta){
  24.         echo '<script>alert("Usuario deletado");location.href="exibe.php";</script>';  
  25.     }else{}
  26. }
  27. ?>
  28. <div id="exibir">
  29.     <table cellpadding="4" cellspacing="3" border="0">
  30.         <tr bgcolor="#ccc">
  31.             <td><strong>Foto</strong></td>
  32.             <td><strong>Nome</strong></td>
  33.             <td><strong>Email</strong></td>
  34.             <td><strong>Cidade</strong></td>
  35.             <td><strong>Endereço</strong></td>
  36.             <td><strong>Estado</strong></td>
  37.             <td><strong>Apagar</strong></td>
  38.         </tr>
  39. <?php
  40. $seleciona = mysql_query("SELECT * FROM usuarios ORDER BY id DESC");
  41. if(@mysql_num_rows($seleciona) == 0){
  42.     echo "Não há usuários cadastrados"; 
  43. }
  44. while($lnuser = mysql_fetch_array($seleciona)){
  45.     $pasta = 'imagens';
  46. ?>
  47.         <tr bgcolor="#ebebeb">
  48.             <td><img src="<?php echo $pasta.'/'.$lnuser['foto'];?>" width="100" height="80" /></td>
  49.             <td><?php echo $lnuser['nome'];?></td>
  50.             <td><?php echo $lnuser['email'];?></td>
  51.             <td><?php echo $lnuser['cidade'];?></td>
  52.             <td><?php echo $lnuser['endereco'];?></td>
  53.             <td><?php echo $lnuser['estado'];?></td>
  54.             <td>
  55.             <form action="" method="post" enctype="multipart/form-data">
  56.                 <input type="hidden" name="id" value="<?php echo $lnuser['id'];?>" />
  57.                 <input type="hidden" name="acao" value="apagar" />
  58.                 <input type="submit" value="Apagar usuario" />
  59.             </form>
  60.             </td>
  61.         </tr>
  62. <?php
  63. }
  64. ?>
  65.     </table>
  66. </div><!--exibir-->
  67. </body>
  68. </html>
Advertisement
Add Comment
Please, Sign In to add comment