Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $conn = new mysqli('localhost', 'ROOT', '', 'chat')
- or die ('Cannot connect to db');
- $result = $conn->query("select userID, userName from user");
- echo "<html>";
- echo "<body>";
- echo "<form action='uusiviesti2.php' method='get'>";
- echo "<select name='userID'>";
- while ($row = $result->fetch_assoc()) {
- unset($id, $name);
- $id = $row['userID'];
- $name = $row['userName'];
- echo "<option value=" . $id . ">" . $name . "</option>";
- }
- echo "</select>";
- echo "<input type='submit'/>";
- echo "</form>";
- echo "</body>";
- echo "</html>";
- ?>
- ------------------
- <?php
- $USERID = $_GET["userID"];
- $conn=new mysqli('localhost', 'ROOT', '', 'chat')
- or die ('Cannot connect to db');
- $result = $conn->query("SELECT messageID FROM message WHERE messageUSER = '$USERID' AND mes$
- echo "<html>";
- echo "<body>";
- echo "<form action='uusiviesti3.php' method='get'>";
- echo "<select name='messageID'>";
- while ($row = $result->fetch_assoc()) {
- unset($id);
- $id = $row['messageID'];
- echo "<option value=" . $id . ">" . $id . "</option>";
- }
- echo "</select>";
- echo "<table style='border: solid 1px black;'>";
- echo "<tr><th>Message</th><th>TO</th></tr>";
- class TableRows extends RecursiveIteratorIterator {
- function __construct($it) {
- parent::__construct($it, self::LEAVES_ONLY);
- }
- function current() {
- return "<td style='width:150px;border:1px solid black;'>" . parent::current(). "</td>";
- }
- function beginChildren() {
- echo "<tr>";
- }
- function endChildren() {
- echo "</tr>" . "\n";
- }
- }
- $servername = "localhost";
- $username = "ROOT";
- $password = "";
- $dbname = "chat";
- try {
- $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $stmt = $conn->prepare("SELECT messageID, messageDATA FROM message WHERE messageUSER = '$USERID$
- $stmt->execute();
- // set the resulting array to associative
- $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
- foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
- echo $v;
- }
- }
- catch(PDOException $e) {
- echo "Error: " . $e->getMessage();
- }
- $conn = null;
- echo "</table>";
- echo "<input type='submit'/>";
- echo "</form>";
- echo "</body>";
- echo "</html>";
- ?>
- ------------------
- <?php
- $messageID = $_GET["messageID"];
- $servername = "localhost";
- $username = "ROOT";
- $password = "";
- $dbname = "chat";
- try {
- $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
- // set the PDO error mode to exception
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $sql = "UPDATE message SET messageREAD=now() WHERE messageID='$messageID' AND messageREAD is nu$
- // Prepare statement
- $stmt = $conn->prepare($sql);
- // execute the query
- $stmt->execute();
- // echo a message to say the UPDATE succeeded
- echo $stmt->rowCount() . " records UPDATED successfully";
- }
- catch(PDOException $e)
- {
- echo $sql . "<br>" . $e->getMessage();
- }
- $conn = null;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement