Advertisement
Guest User

Untitled

a guest
Apr 4th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. <html>
  2. <script src="js/funcao.js"></script>
  3. </head>
  4. <body>
  5. <div data-role="page" id="paginal">
  6. <div data-role="header">
  7. <h1>Registros</h1>
  8. </div>
  9. <div data-role="main" class="ui-content">
  10. <label>Nome</label>
  11. <input id="nome" type="text" name="nome" /> <br>
  12. <label>Sobrenome</label>
  13. <input id="sobrenome" type="text" name="sobrenome" /> <br>
  14. <button id="inclusao">Incluir</button>
  15. <HR>
  16. <a href="#paginal2" class="ui-btn ui-btn-corner-all">Visualizar Cadastros</a>
  17. </HR>
  18. </div>
  19. </div>
  20. <div data role="page" id="paginal2">
  21. <div data-role="header">
  22. <a href="#paginal1" data-rel="back" class="ui-btn-left ui-btn ui-btn-icon-notext ui-corner-all ui-icon-back">Voltar</a>
  23. <h1>Listar Usuario</h1>
  24. </div>
  25. <div data-role="main" class="ui-content">
  26. <p id="listarusuario"></p>
  27. </div>
  28. </div>
  29.  
  30. </body>
  31. </html>
  32.  
  33. <?php
  34.  
  35. //$serve = mysql_connect('localhost', 'root', '');
  36.  
  37. $servername = "localhost";
  38. $username = "root";
  39. $password = "";
  40. $dbname = "registro";
  41.  
  42. // Create connection
  43. $serve = new mysqli($servername, $username, $password, $dbname);
  44.  
  45. if (!$serve) {
  46. echo 'erro';
  47. }
  48.  
  49. //$db = mysql_select_db('registro', $serve);
  50.  
  51. if($GET['acao'] == 'inclusao') {
  52.  
  53. $nome = $_GET['nome'];
  54. $sobrenome = $_GET['sobrenome'];
  55.  
  56. $SQL = "insert INTO usuario (nome,sobrenome) VALUES ('$nome', '$sobrenome') ";
  57. $re = mysqli_query($SQL, $serve);
  58. }
  59.  
  60. if ($_GET['acao'] == 'listarusuario') {
  61.  
  62. $SQL = "SELECT * FROM usuario";
  63.  
  64. $re = mysqli_num_rows($re);
  65.  
  66. if($num > 0) {
  67.  
  68. while($Linha = mysqli_fetch_object($re)) {
  69. echo "<b>Nome:</b> {$Linha->nome} <b><br></b> <b>Sobrenome:</b> {$Linha->sobrenome} </br><hr>";
  70. }
  71. }
  72. else {
  73. echo 'no registered users';
  74. }
  75. }
  76. ?>
  77.  
  78. $(document).ready(function) {
  79. var $server;
  80. $server = 'http://localhost:81/xampp/porto/www/';
  81.  
  82. $('#inclusao').on('click', function() {
  83. $nome = $('#nome').val();
  84. $sobrenome = $('#sobrenome').val();
  85.  
  86. $.ajax({
  87. type: "get",
  88. url: $server-"/connecta.php",
  89. data: "nome="+$nome+"&sobrenome="+$sobrenome+"&acao=inclusao",
  90. sucess: function(data) {
  91. intel.xdk.notification.alert('usuario cadastr:','aviso!','OK');
  92. Lista();
  93. }
  94. });
  95. });
  96.  
  97. function Lista() {
  98. $.ajax({
  99. type: "get",
  100. dataType: 'html',
  101. url: $server+"/conecta.php",
  102. data: "acao=listarusuario",
  103. sucess: function(data) {
  104. $('#listarusuario').html(data);
  105. }
  106. });
  107. }
  108. Lista();
  109. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement