Jump to content

Need A Little Help :)


MatthewRidings

Recommended Posts

Hi all iv'e been attempting to code up a shout box for my site basically iv'e coded it all up and it works great apart from the posting side of things it will post the time and the user that's logged in but its not posting the message into the log file and that is what I'm currently struggling to fix :( might be a simple fix but Iv'e not done any coding for along time and though I'd try getting back into it any help would be great

here is a screen shot to what I get when I post

captureezg.png

 

the chat.php

<?php
include 'include/database.php';
if(!isset($_SESSION['signed_in'])){
}
else{
?>
<div id="chatwrapper">
<div id="chatmenu">
 <p class="welcome">Welcome, <b><?php echo $_SESSION['user_name']; ?></b></p>
 <div style="clear:both"></div>
</div>
<div id="chatbox"><?php
if(file_exists("log.html") && filesize("log.html") > 0){
 $handle = fopen("log.html", "r");
 $contents = fread($handle, filesize("log.html"));
 fclose($handle);

 echo $contents;
}
?></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>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/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.html",
  cache: false,
  success: function(html){ 
   $("#chatbox").html(html); //Insert chat log into the #chatbox div   
   var newscrollHeight = $("#chatbox").attr("scrollHeight") - 50;
   if(newscrollHeight > oldscrollHeight){
 $("#chatbox").animate({ scrolltop: newscrollHeight }, 'normal'); //Autoscroll to bottom of div
   }   
    },
 });
}
setInterval (loadLog, 2500); //Reload file every 2.5 seconds
});
</script>
<?php
}
?>

 

this is the post.php

 

<?
session_start();


if(isset($_SESSION['user_name'])){
$text = $_POST['text'];

$fp = fopen("log.html", 'a');
fwrite($fp, "<div class='msgln'>(".date("g:i A").") <b>".$_SESSION['user_name']."</b>: ".stripslashes(htmlspecialchars($text))."<br></div>");
fclose($fp);
}
?>

 

Personally I think its trying to post to the message to the database which I don't want it to do as it suppose to post to the html log file.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.