Search the Community
Showing results for tags 'live chat'.
-
I have live chat that is supposed to display the "sender" and the "message", but instead give me some weird result. script: function get_msg(){ global $con; $query = "SELECT Sender, Message FROM chat"; $run = mysqli_query($con, $query); $messages = array(); while($message = mysqli_fetch_assoc($run)){ $messages = array('sender' => $message['Sender'], 'message' => $message['Message']); } return $messages; } <div id="messages"> <?php $messages = get_msg(); foreach($messages as $sender => $message){ echo "Sender: " . $sender . "<br >"; echo "Message: " . $message . "<br />"; } ?></div> this is what it outputs: Message has been sent. Sender: senderMessage: hiSender: messageMessage: message
-
this is a little reference from my live chat script, but it wont work. The error message is variable $con is not defined, but it is clearly defined. $con = mysqli_connect("localhost","root","123","chat") or die(mysqli_error($con));function get_msg(){ $query = mysqli_query($con, "SELECT Sender, Message FROM chat"); $run = mysqli_query($con, $query); $messages = array(); while($message = mysqli_fetch_assoc($run)){ $messages = array('sender' => $message['Sender'], 'message' => $message['Message']); } return $messages; }