Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include 'db.php';
- ?>
- <!doctype html>
- <html lang = "en">
- <head>
- <title>Chat With Me</title>
- <link rel = "stylesheet" href = "style/chatstyle.css"/>
- <script>
- function ajax() {
- var req = new XMLHttpRequest();
- req.onreadystatechange = function() {
- if (req.readyState == 4 && req.status == 200) {
- document.getElementById('chat').innerHTML = req.responseText;
- }
- }
- req.open('GET','data.php',true);
- req.send();
- }
- setInterval(function() {ajax()}, 1000 );
- </script>
- </head>
- <body onload="ajax();">
- <div id = "container">
- <div id = "chat-box">
- <div id = "chat">
- </div>
- </div>
- <form method = "post" action = "chat.php">
- <input type = "text" name = "name" placeholder="Name:"/>
- <textarea name = "entermessage" placeholder="Enter Message:"></textarea>
- <input type = "submit" name = "submit" value = "Send"/>
- </form>
- <?php
- if($_POST['submit']) {
- $name = $_POST['name'];
- $message = $_POST['entermessage'];
- $query = "INSERT INTO CHAT (name, message) VALUES ('$name', '$message')";
- $run = $con->query($query);
- if($run) {
- echo "<embed loop='false' hidden = 'true'/>";
- }
- }
- ?>
- </div>
- </body>
- </html>
- <?php
- include 'db.php';
- $query = "SELECT * FROM chat ORDER BY id DESC";
- $run = $con->query($query);
- while($row = $run->fetch_array()) :
- ?>
- <div id = "chat-data">
- <span class = "name"><?php echo $row['name']; ?> </span> :
- <span class = "message"><?php echo $row['message']; ?> </span>
- <span class = "time"><?php echo $row['date']; ?></span>
- </div>
- <?php endwhile; ?>
- <?php
- $host = "******";
- $username = "*******";
- $password = "*******";
- $db_name = "******";
- $con = new mysqli($host, $username, $password, $db_name);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement