Simple staff chat

So I’ve been working on this for a couple of hours now and I seriously can’t get it to work. I have tried downloading and modifying a simple php chat script from here: https://www.logicspice.com/chat-room-script
But I just can’t get it to work for some reason.

I did modify it a small amount just to get it to attempt to pull information from the steam login method that I have users using. I was able to get it to show up for users, and show online users perfectly fine. The only thing that is not working is when you try to post something it brings up the sending message then it goes away and will not post.

This is the script that gets executed to post the message, but as I can see obviously does not work. Just about everything else is the same as the original script except for the method of logging in.

I changed $_SESSION[‘user’] to userid as that is what I have been using in the past. Here is the post code that I am using.

I also want to add that although the database name is called support_chat, it’s not a support chat it’s just a general chat room for the support staff to use.

<?php
include("config.php");
if(!isset($_SESSION['userid']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH'])=='xmlhttprequest'){
 die("<script>window.location.reload()</script>");
}
if(isset($_SESSION['userid']) && isset($_POST['msg'])){
    $staff = $_SESSION['user'];
}else{
    $staff = '';
}
 $msg=htmlspecialchars($_POST['msg']);
 if($msg!=""){
  $sql=$dbh->prepare("INSERT INTO support_chat (username,msg,posted) VALUES ('".$Staff."',?,NOW())");
  $sql->execute(array($_SESSION['userid'],$msg));
 }
}
?>

This isn’t a proper prepare statement.

  $sql=$dbh->prepare("INSERT INTO support_chat (username,msg,posted) VALUES (?,?,now())");
  $sql->execute(array($_SESSION['userid'],$msg));

You can further refine this by making the defaul value on the posted column a timestamp or datetime, then you wont need to insert a value as it will be done for you.

Sponsor our Newsletter | Privacy Policy | Terms of Service