-1

the success function is working but the data is not going in the database

$(document).ready(function() {
    $("#ChatText").keyup(function(e){
        if(e.keyCode == 13) {
            var ChatText = $("#ChatText").val();
            $.ajax({
                type:'POST',
                url:'InsertMessage.php',
                data:{ChatText:ChatText},
                success:function(){
                    $("#ChatText").val("");
                }
            });
        }
    });
    setInterval(function(){
        $("#ChatMessages").load("DisplayMessages.php");
    },15000000);

    $("#ChatMessages").load("DisplayMessages.php");
});

PHP

<?php
session_start();
include "connectToDB.php";

if(isset($_POST['ChatText'])){
    $uid = $_SESSION['userid'];
    $gid = $_SESSION['GameId'];
    $ct = $_POST['ChatText'];
    $sql = "INSERT INTO `chats`( `ChatUserId`, `chatGameId`, `ChatText`) VALUES ('$uid','$gid',$ct);";
    $result = mysqli_query($_db , $sql);
}
?>
M. Eriksson
  • 13,450
  • 4
  • 29
  • 40

1 Answers1

0

one thing u could do to debug is that echo your sql query and see if you get the correct query that works. You can event try out that query in phpMyAdmin and see whats going on. Hard to tell anything without debug.