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 8447009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:04:44+00:00 2026-06-10T10:04:44+00:00

Hey guys I am having a VERY difficult time with a specific problem in

  • 0

Hey guys I am having a VERY difficult time with a specific problem in hand. I’m trying to create a database driven chat room that fetches posts with AJAX. However, when calling to fetch data with AJAX, I get an undefined index warning. I use the setinterval() function to call the javascript function that contains the AJAX. I get this warning when the timing of the setinverval() function is reached. How can I code this so when that variable is empty and the setinterval() function is reached, I stop getting the warning? Thanks in advance to all who will help. Btw this is my very first post so if additional information is needed please let me know. Thanks again!!

here is the chatRoom.php file

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org
/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Chat - Customer Module</title>
<link type="text/css" rel="stylesheet" href="style.css" />

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery
/1.3/jquery.min.js"></script>
<script type="text/javascript">
// jQuery Document
$(document).ready(function(){
//If user submits the form
$("#submitmsg").click(function(){   
    var clientmsg = $("#usermsg").val();
    $.post("post.php", {text: clientmsg});              
    $("#usermsg").attr("value", "");
    return false;
});

//Load the file containing the chat log
function loadLog(){     
    var oldscrollHeight = $("#chatbox").attr("scrollHeight") - 20;
    $.ajax({
        url: "log.php",
        cache: false,
        success: function(html){        
            $("#chatbox").html(html);
                    //Insert chat log into the#chatboxdiv               
            var newscrollHeight = $("#chatbox").attr("scrollHeight")
   - 20;
            if(newscrollHeight > oldscrollHeight){
$("#chatbox").animate({scrollTop:newscrollHeight},'normal');
   //Autoscroll to  bottom of div
            }               
        }
    });
}
setInterval (loadLog, 1500);    //Reload file every 2.5 seconds

//If user wants to end session
$("#exit").click(function(){
    var exit = confirm("Are you sure you want to end the session?");
    if(exit==true){window.location = 'index.php?logout=true';}      
});
});
</script>

</head>
<?php
    include('functions.php'); 
    session_start();
?>

<div id="wrapper">
<div id="menu">
    <p class="welcome">Welcome, <b><?php echo $_SESSION['user']; ?></b></p>
    <p class="logout"><a id="exit" href="#">Exit Chat</a></p>
    <div style="clear:both"></div>
</div>  
<div id="chatbox">
        <?php
            loadPosts();
        ?>
    </div>

<form name="message" action="">
    <input name="usermsg" type="text" id="usermsg" size="63" />
    <input name="submitmsg" type="submit"  id="submitmsg" value="Send" />
</form>
</div>
</body>
</html>

Here is the php.post file

<?
include('functions.php');
session_start();
if(isset($_SESSION['user'])){
$text = $_POST['text'];

    $uName = $_SESSION['user'];
    $time = date("h:i A");

    postComment($time, $uName, $text);
}       
?>

The functions.php file

<?php
include('connect.php');
function loadPosts(){

    $query = mysql_query("SELECT * FROM chat") or die(mysql_error());

    if(mysql_num_rows($query) == 0){
        echo "No Posts Were Found";
    }

    while($post = mysql_fetch_assoc($query))
    {
        echo "(" . $post['time'] . ") <b>" . $post['user'] . "</b>: " . $post['text']
. "<br />";
    }

}

function postComment($time, $userN, $userMessage){
    mysql_query("INSERT INTO chat 
Values(null, '$time', '$userN', '$userMessage')") or die(mysql_error());
}

function exitChat(){
    header("Location: index.php");
}

?>

Finally the new file log.php

<?php
include('functions.php');
session_start();
if(isset($_SESSION['user']))
    loadPosts();    
?>
  • 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-10T10:04:46+00:00Added an answer on June 10, 2026 at 10:04 am

    Hey guys I figured it out!! Wow that took me almost a month to figure out!! Apparently, I was forced to separate the postComment() and loadPosts() functions into their own files. I left the postComment() inside the post.php page but placed the loadPosts() in another page. I am not really sure why this works but it does. It’s not giving me an index error or removing all the chat content. I’ll post the code if anyone is interested in checking it out! Btw, I wanted to thank everyone that contributed to this post and tried helping. Thank you!!

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

Sidebar

Related Questions

Hey guys im having a problem trying to program out a set of logic.
Hey guys im having a problem. Im trying to make a website with 3
Hey guys I'm having the damnedest time trying to pull in new entries (or
hey guys having this really simple problem but cant seem to figure out have
Hey guys I'm having such a hard time of it today. I have a
Hey guys (and gals) I'm having a problem using Assembly GetExportedTypes() in .NET 4.0.
Hey guys, I'm having a problem with IE7, my menu always drops down behind
hey guys, just having a bit of difficulty with a query, i'm trying to
Hey guys I am having a lot of trouble trying to understand this and
Hey guys I am having trouble trying to convert my web app to support

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.