Charles_Mad

update-cidade.php

Jun 10th, 2015
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. <?php
  2. function eg_update_cidade (){
  3. global $wpdb;
  4. $id = $_GET["id"];
  5. $set_nome=$_POST["nome_cidade"];
  6. $set_estado=$_POST["estado"];
  7.  
  8. //update
  9. if(isset($_POST['update'])){
  10. $wpdb->update(
  11. 'cidade', //table
  12. array('nome_cidade' => $set_nome), //data
  13. array('estado' => $set_estado), //data
  14. array( 'id_cidade' => $id ), //where
  15. array('%s'), //data format
  16. array('%s'), //data format
  17. array('%s') //where format
  18. );
  19. }
  20. //delete
  21. else if(isset($_POST['delete'])){
  22. $wpdb->query($wpdb->prepare("DELETE FROM cidade WHERE id_cidade = %s",$id));
  23. }
  24. else{//selecionando valor para atualizar
  25. $cidades = $wpdb->get_results($wpdb->prepare("SELECT id_cidade,nome_cidade,estado from cidade where id_cidade=%s",$id));
  26. foreach ($cidades as $s ){
  27. $nome=$s->nome_cidade;
  28. }
  29. }
  30. ?>
  31. <link type="text/css" href="<?php echo WP_PLUGIN_URL; ?>/GerePRO/style-admin.css" rel="stylesheet" />
  32. <div class="wrap">
  33. <h2>Cidades</h2>
  34.  
  35. <?php if($_POST['delete']){?>
  36. <div class="updated"><p>Cidade Deletada</p></div>
  37. <a href="<?php echo admin_url('admin.php?page=lista_cidades')?>">&laquo; Voltar para Lista de Cidades</a>
  38.  
  39. <?php } else if($_POST['update']) {?>
  40. <div class="updated"><p>Cidade Atualizada</p></div>
  41. <a href="<?php echo admin_url('admin.php?page=lista_cidades')?>">&laquo; Voltar para Lista de Cidades</a>
  42.  
  43. <?php } else {?>
  44. <form method="POST" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
  45. <table class='wp-list-table widefat fixed'>
  46. <tr><th>Nome</th><td><input type="text" name="nome_cidade" value="<?php echo $set_nome;?>"/></td></tr>
  47. <tr><th>Estado</th><td><input type="text" name="estado" value="<?php echo $set_estado;?>"/></td></tr>
  48. </table>
  49. <input type='submit' name="update" value='Save' class='button'> &nbsp;&nbsp;
  50. <input type='submit' name="delete" value='Delete' class='button' onclick="return confirm('&iquest;Confirma Exclusão?')">
  51. </form>
  52. <?php }?>
  53.  
  54. </div>
  55. <?php
  56. }
Advertisement
Add Comment
Please, Sign In to add comment