I'm making a chat system between users and operator,which contain of chatbox written by html and posechat.php to bring the data from database to the chatbox via jquery.
<div id="chatbox"></div>
<form>
<input name="usermsg" type="text" id="usermsg" size="63" />
<input type="hidden" id="uid" name="uid" value="<?php echo $uid; ?>">
<input name="submitmsg" type="submit" id="submitmsg" value="Send" />
</form>
jquery:
$("#submitmsg").click(function () {
var clientmsg = $("#usermsg").val();
var clientid = $("#uid").val();
$.post("includes/postchat.php", {text: clientmsg,uid: clientid});
$.post("includes/posechat.php", {text: clientmsg,uid: clientid});
$("#usermsg").attr("value", "");
return false;
});
$.ajaxSetup({cache: false});
setInterval(function () {
$('#chatbox').load('includes/posechat.php');
}, 1000);
});
I put an username in the tail of chatbox to identify the the user ( ex: chatsystem.html?user=Adam).I want to fetch that data($uid) to the posechat.php for sql statement to display the right output in the chatbox but it doesnt seem to work, got an error: Undefined index Here's the posechat.php:
session_start();
$user = $_SESSION['u_uid'];
include('dbh-inc.php');
$uid = $_POST['uid'];
echo $uid;