Advertisement
Guest User

Untitled

a guest
Sep 25th, 2012
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!doctype html>
  2.  
  3. <?php
  4. require_once('get.php');
  5.  
  6. ?>
  7.  
  8. <html class="no-js" lang="en">
  9. <head>
  10. <meta charset="utf-8">
  11.  
  12. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  13.  
  14. <title></title>
  15. <meta name="description" content="">
  16.  
  17.  
  18. <meta name="viewport" content="width=device-width">
  19.  
  20.  
  21.  
  22.  
  23.  
  24. </head>
  25. <body>
  26. <div id="wrap-body">
  27.  
  28.  
  29. <form action="" method="post">
  30. <input type="text" name="username" id="username">
  31.  
  32. <input type="text" name="msg" id="msg">
  33.  
  34. <input type="button" id="submit" value="Send">
  35.  
  36. </form>
  37.  
  38.  
  39. <div id="info">
  40.  
  41.  
  42. </div>
  43. </div>
  44.  
  45.  
  46.  
  47.  
  48. <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
  49. <script>window.jQuery || document.write('<script src="js/jquery-1.7.2.min.js"><\/script>')</script>
  50. <script src="js/login.js"></script>
  51.  
  52.  
  53. <script>
  54. var _gaq=[['_setAccount','UA-XXXXX-X'],['_trackPageview']];
  55. (function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
  56. g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
  57. s.parentNode.insertBefore(g,s)}(document,'script'));
  58. </script>
  59. </body>
  60.  
  61. <script>
  62. $(document).ready(function (){
  63.  
  64.  
  65.  
  66.  
  67. $('#submit').click(function (){
  68. var username = $('#username').val();
  69. var msg = $('#msg').val();
  70.  
  71. $.ajax({
  72. type: 'POST',
  73. url: 'get.php',
  74. dataType: 'json',
  75. data:{'username': username, 'msg':msg},
  76. success: function (data){
  77.  
  78. $.each(data, function(i,item) {
  79.  
  80. $('#info').append("<p> you are:"+data[i].username+"</p> <p> your message is:"+data[i].mesg);
  81.  
  82. });​
  83.  
  84. }
  85. });
  86.  
  87. });
  88.  
  89.  
  90. });
  91.  
  92.  
  93. </script>
  94.  
  95.  
  96.  
  97. </html>
  98.  
  99. PHP:
  100.  
  101. <?php
  102.  
  103. $host='localhost';
  104. $username='root';
  105. $password='12345';
  106. $db = 'feeds';
  107.  
  108.  
  109.  
  110. $connect = mysql_connect($host,$username,$password) or die("cant connect");
  111. mysql_select_db($db) or die("cant select the".$db);
  112.  
  113.  
  114. $username = $_POST['username'];
  115.  
  116. $msg = $_POST['msg'];
  117.  
  118. $insert = "INSERT INTO info(user_name,message) VALUES('$username','$msg')";
  119.  
  120. if(@!mysql_query($insert)){
  121.  
  122. die('error insertion'.mysql_error());
  123.  
  124. }
  125.  
  126.  
  127. $get = "SELECT * FROM info ";
  128.  
  129. $result=mysql_query($get)or die(mysql_error());
  130.  
  131.  
  132.  
  133. $inside_counter = mysql_num_rows($result);
  134.  
  135.  
  136.  
  137.  
  138. $data=array();
  139. while ($row = mysql_fetch_array($result))
  140. {
  141. $data[] = array(
  142. 'username'=>$row['user_name'],
  143. 'mesg'=>$row['message'],
  144. 'counter'=>$inside_counter
  145. );
  146. }
  147.  
  148. echo json_encode($data);
  149.  
  150.  
  151.  
  152. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement