Advertisement
Guest User

Untitled

a guest
Mar 9th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1.  
  2.  
  3. <?php
  4.  
  5. $conn = new mysqli('localhost', 'ROOT', '', 'chat')
  6. or die ('Cannot connect to db');
  7.  
  8. $result = $conn->query("select userID, userName from user");
  9.  
  10. echo "<html>";
  11. echo "<body>";
  12. echo "<form action='uusiviesti2.php' method='get'>";
  13. echo "<select name='userID'>";
  14.  
  15. while ($row = $result->fetch_assoc()) {
  16.  
  17. unset($id, $name);
  18. $id = $row['userID'];
  19. $name = $row['userName'];
  20. echo "<option value=" . $id . ">" . $name . "</option>";
  21. }
  22.  
  23. echo "</select>";
  24. echo "<input type='submit'/>";
  25. echo "</form>";
  26.  
  27. echo "</body>";
  28. echo "</html>";
  29.  
  30. ?>
  31. ------------------
  32. <?php
  33.  
  34. $USERID = $_GET["userID"];
  35. $conn=new mysqli('localhost', 'ROOT', '', 'chat')
  36. or die ('Cannot connect to db');
  37.  
  38. $result = $conn->query("SELECT messageID FROM message WHERE messageUSER = '$USERID' AND mes$
  39.  
  40. echo "<html>";
  41. echo "<body>";
  42. echo "<form action='uusiviesti3.php' method='get'>";
  43. echo "<select name='messageID'>";
  44.  
  45. while ($row = $result->fetch_assoc()) {
  46.  
  47. unset($id);
  48. $id = $row['messageID'];
  49. echo "<option value=" . $id . ">" . $id . "</option>";
  50. }
  51.  
  52. echo "</select>";
  53.  
  54.  
  55. echo "<table style='border: solid 1px black;'>";
  56. echo "<tr><th>Message</th><th>TO</th></tr>";
  57.  
  58. class TableRows extends RecursiveIteratorIterator {
  59. function __construct($it) {
  60. parent::__construct($it, self::LEAVES_ONLY);
  61. }
  62.  
  63. function current() {
  64. return "<td style='width:150px;border:1px solid black;'>" . parent::current(). "</td>";
  65. }
  66.  
  67. function beginChildren() {
  68. echo "<tr>";
  69. }
  70.  
  71. function endChildren() {
  72. echo "</tr>" . "\n";
  73. }
  74. }
  75.  
  76. $servername = "localhost";
  77. $username = "ROOT";
  78. $password = "";
  79. $dbname = "chat";
  80.  
  81. try {
  82. $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  83. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  84. $stmt = $conn->prepare("SELECT messageID, messageDATA FROM message WHERE messageUSER = '$USERID$
  85.  
  86. $stmt->execute();
  87.  
  88. // set the resulting array to associative
  89. $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
  90. foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
  91. echo $v;
  92. }
  93. }
  94. catch(PDOException $e) {
  95. echo "Error: " . $e->getMessage();
  96. }
  97. $conn = null;
  98. echo "</table>";
  99.  
  100. echo "<input type='submit'/>";
  101. echo "</form>";
  102. echo "</body>";
  103. echo "</html>";
  104.  
  105. ?>
  106.  
  107. ------------------
  108.  
  109. <?php
  110. $messageID = $_GET["messageID"];
  111. $servername = "localhost";
  112. $username = "ROOT";
  113. $password = "";
  114. $dbname = "chat";
  115.  
  116. try {
  117. $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  118. // set the PDO error mode to exception
  119. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  120.  
  121. $sql = "UPDATE message SET messageREAD=now() WHERE messageID='$messageID' AND messageREAD is nu$
  122.  
  123. // Prepare statement
  124. $stmt = $conn->prepare($sql);
  125.  
  126. // execute the query
  127. $stmt->execute();
  128.  
  129. // echo a message to say the UPDATE succeeded
  130. echo $stmt->rowCount() . " records UPDATED successfully";
  131. }
  132. catch(PDOException $e)
  133. {
  134. echo $sql . "<br>" . $e->getMessage();
  135. }
  136.  
  137. $conn = null;
  138. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement