Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8815963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:30:19+00:00 2026-06-14T04:30:19+00:00

It’s my first day here, I thought you guys could help me. So, I’m

  • 0

It’s my first day here, I thought you guys could help me. So, I’m working on this kind of chatting service for a friend. I want it to auto update anything inside the div tags that has an id of messages. I tried adding some javascript and stuff from other posts, but they just made it worse. So, if anyone could fix it and comment, or give me suggestions. I want it as soon as someone posted something, it updates the posts in the div tags with the id of messages.

<?php

session_start();

if(!isset($_SESSION['username']))
{

header("Location: /index.php");

}

?>
<html>

<head>

<title>
House Email System
</title>

<style>

body
{
background: #383838;
font-family: Arial;
color: #444444;
position: absolute;
top: 50%;
left: 50%;
margin-top: -75px;
margin-left: -150px;
}

form
{
background: #ffffff;
width: 270px;
border-radius: 15px;
box-shadow: 3px 3px 6px 1px #303030;
}

input
{
margin-left: 15px;
}

p
{
margin-left: 15px;
}

error
{
padding:2px 4px;
margin:0px;
border:solid 1px #FBD3C6;
background:#FDE4E1;
color:#CB4721;
font-size:14px;
font-weight:bold;
}

div
{
background: #f0f0f0;
}

hr
{
color: #d0d0d0;
background-color: #d0d0d0;
height: 3px;
border: 0px;
}

username
{
margin-left: 5px;
}

message
{
margin-left: 10px;
}

</style>

</head>

<body>

<?php

$connect = mysql_connect("localhost", "root", "*******");
mysql_select_db("*******");

$username = $_SESSION['username'];
$message = $_POST['message'];
$submit = $_POST['submit'];

if($submit)
{

if($message)
{

mysql_query("INSERT INTO messages VALUES('', '$username', '$message')");

}
else
{

?>

<center>

<error>Please enter a message to send.</error> <br />

</center>

<br />

<?php

}

}

?>

<form action="active.php" method="POST">

<br />

<p>Message</p>
<input type="text" name="message" /> <br />

<br />

<input type="submit" name="submit" value="Submit" /> <br />

<br />

<?php

$query = mysql_query("SELECT * FROM messages ORDER BY id DESC");
$num_rows = mysql_num_rows($query);

if($num_rows > 0)
{

while($row = mysql_fetch_assoc($query))
{

$username = $row['username'];
$message = $row['message'];

?>

<div id="messages">

<br /> <username><b><?php echo $username; ?></b></username>

<hr />

<message><?php echo $message; ?></message> <br />

<br /> </div> <br />

<?php

}

}
else
{

?>

<center>

<error>There are no messages to display.</error> <br />

</center>

<br />

<?php

}

?>

</form>

</body>

</html>

I hope you guys can help me, thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T04:30:20+00:00Added an answer on June 14, 2026 at 4:30 am

    First create a page message.php as:

            <?php
    session_start();
    ?>
    <html>
    
    <head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"     type="text/javascript"></script>
    
    <script type="text/javascript">
            $(document).ready(function()
            {
                $('#submit').click(function()
                {
                //alert("hello");
               // ss=document.getElementById("message").value;
    
                    $.ajax({
                          type : 'POST',
                          url : 'active.php',
    
                         data: {
                         messages :$('#message').val()
                           },
                          success : function(data){
    
                             $('#messages').html(data);
    }
    
                    });
    
    
                });
            });
        </script>
    
    <title>
    House Email System
    </title>
    
    <style>
    
    body
    {
    background: #383838;
    font-family: Arial;
    color: #444444;
    position: absolute;
    top: 50%;
    left: 50%;
    margin-top: -75px;
    margin-left: -150px;
    }
    
    form
    {
    background: #ffffff;
    width: 270px;
    border-radius: 15px;
    box-shadow: 3px 3px 6px 1px #303030;
    }
    
    input
    {
    margin-left: 15px;
    }
    
    p
    {
    margin-left: 15px;
    }
    
    error
    {
    padding:2px 4px;
    margin:0px;
    border:solid 1px #FBD3C6;
    background:#FDE4E1;
    color:#CB4721;
    font-size:14px;
    font-weight:bold;
    }
    
    div
    {
    background: #f0f0f0;
    }
    
    hr
    {
    color: #d0d0d0;
    background-color: #d0d0d0;
    height: 3px;
    border: 0px;
    }
    
    username
    {
    margin-left: 5px;
    }
    
    message
    {
    margin-left: 10px;
    }
    
    </style>
    
    </head>
    
    <body>
    
    
    
    <center>
    
    <error>Please enter a message to send.</error> <br />
    
    </center>
    
    <br />
    
    
    
    <form action="active.php" method="POST">
    
    <br />
    
    <p>Message</p>
    <input type="text" name="message" id="message" /> <br />
    
    <br />
    
    <input type="button" id="submit" name="submit" value="Submit" /> <br />
    </form>
    <br />
    
    <div id="messages">
    
    
    
    </div>
    
    </body>
    
    </html>
    
    
    
    <script language="JavaScript"><!--
    // v3 compatible:
    function doSomething() {
       // do something here...
       $.ajax({
                          type : 'POST',
                          url : 'active.php',
    
                         data: {
                         messages :$('#message').val()
                           },
                          success : function(data){
    
                             $('#messages').html(data);
    }
    
                    });
       setTimeout('doSomething()',3000);
    }
    setInterval('doSomething()',3000);
    //--></script>
    

    Then Create a page active.php as

    <?php
    session_start();
    $connect = mysql_connect("localhost", "root", "");
    mysql_select_db("test");
    
    $username=$_SESSION['username'];
    $message=$_POST['messages'];
    
    if($message!="")
    {
    mysql_query("INSERT INTO messages VALUES('', '$username', '$message')");
    }
    
    $query = mysql_query("SELECT * FROM messages ORDER BY id DESC limit 1,0");
    $num_rows = mysql_num_rows($query);
    
    if($num_rows > 0)
    {
    
    while($row = mysql_fetch_assoc($query))
    {
    
    $username = $row['username'];
    $message = $row['message'];
    
    ?>
    
    <div>
    
    <br /> <username><b><?php echo $username; ?></b></username>
    
    <hr />
    
    <message><?php echo $message; ?></message> <br />
    
    <br /> </div>
    
    
    <br />
    
    <?php
    
    }
    
    }
    else
    {
    
    echo"No message to show";
    }
    ?>
    

    This is very general chat.Now you need to change it according to your requirements.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.