Advertisement
Guest User

Untitled

a guest
Aug 12th, 2016
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. <html>
  2. <head>
  3. <script>
  4. function showUser(str) {
  5. if (str == "") {
  6. document.getElementById("txtHint").innerHTML = "";
  7. return;
  8. } else {
  9. if (window.XMLHttpRequest) {
  10. // code for IE7+, Firefox, Chrome, Opera, Safari
  11. xmlhttp = new XMLHttpRequest();
  12. } else {
  13. // code for IE6, IE5
  14. xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  15. }
  16. xmlhttp.onreadystatechange = function() {
  17. if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
  18. document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
  19. }
  20. };
  21. xmlhttp.open("GET","testmysql.php?q="+str,true);
  22. xmlhttp.send();
  23. }
  24. }
  25. </script>
  26. </head>
  27. </html>
  28.  
  29. <html>
  30. <head>
  31. <script type="text/javascript" src="show.js"></script>
  32. <style>
  33. table {
  34. width: 100%;
  35. border-collapse: collapse;
  36. }
  37.  
  38. table, td, th {
  39. border: 1px solid black;
  40. padding: 5px;
  41. }
  42.  
  43. th {text-align: left;}
  44. </style>
  45. </head>
  46. <body>
  47.  
  48.  
  49. <?php
  50.  
  51. //Sample Database Connection Script
  52.  
  53. //Setup connection variables, such as database username
  54. //and password
  55. $hostname="localhost";
  56. $username="root";
  57. $password="";
  58. $dbname="grocery";
  59. $usertable="grocery";
  60. $yourfield = "NAME";
  61. $q = intval($_GET['q']);
  62. //Connect to the database
  63. $connection = mysqli_connect($hostname, $username, $password);
  64. mysqli_select_db($connection, $dbname);
  65. $query="SELECT * FROM user WHERE id = '".$q."'";
  66. $result = mysqli_query($connection,$query);
  67.  
  68. echo "<table>
  69. <tr>
  70. <th>Name</th>
  71. <th>Price</th>
  72. <th>Amount</th>
  73. </tr>";
  74. if($result){
  75. while($row = mysqli_fetch_array($result)) {
  76. echo "<tr>";
  77. echo "<td>" . $row['NAME'] . "</td>";
  78. echo "<td>" . $row['PRICE'] . "</td>";
  79. echo "<td>" . $row['AMOUNT'] . "</td>";
  80. echo "</tr>";
  81. }
  82. }
  83. echo "</table>";
  84. mysqli_close($connection);
  85. /*
  86. //Setup our query
  87. //$query = "SELECT * FROM $usertable";
  88.  
  89. Run the Query
  90. $result = mysqli_query($connection,$query);
  91.  
  92. //If the query returned results, loop through
  93. // each result
  94. if($result)
  95. {
  96. while($row = mysqli_fetch_array($result))
  97. {
  98. $name = $row["$yourfield"];
  99. echo "Name: " . $name;
  100.  
  101. }
  102. }
  103. */
  104. ?>
  105. </body>
  106. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement