Empty and Append return no value

0

I'm having the problem that my empty (). append (); does not return any php value in the div and I also can not insert anything inside it, even inside the html itself. It's as if it fades, but for a second I see that the content typed in HTML is there, but it disappears again. Can anyone help me?

HTML

 <!DOCTYPE html>
<html>
<head>
    <title>Sala <?=$nick?></title>
    <meta charset="utf-8">
    <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.js"></script><scripttype="text/javascript" src="js/bootstrap.js"></script>
    <script type="text/javascript" src="js/main.js"></script>
    <link rel="stylesheet" type="text/css" href="css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="css/style.css">
</head>

<body style="background-color: #1C1C1C;" onload="carregaMensagem()">

<div class="container">
    <div id="mensagens">
    </div>

    <form onsubmit="enviar(); return false" method="post" action="">
        <input type="text" id="mensagem" placeholder="Digite sua mensagem" class="form-control">
        <input type="submit" style="display:none;">
    </form>

</div>

</body>
</html>

PHP

<?php 
    require_once("inc/config.php"); //conexão com banco

    if (isset($_SESSION['nickname'])) {
        $sql = msql_query("SELECT * FROM mensagem");
        if (mysql_num_rows($sql) > 0) {
            while ($ln = mysql_fetch_assoc($sql)) {
                echo '<p>Seja Bem vindo'.$_SESSION['nickname'].'</p>';
                echo '<p>Digita /sair deslogar do chat</p>';
                $nick = strip_tags($ln['nickname']);
                $mensagem = htmlspecialchars($ln['mensagem']);
                echo "<p>".$nick.":".$mensagem."</p>";
            }
        } else {
            echo '<p>Seja Bem vindo'.$_SESSION['nickname'].'</p>';
            echo '<p>Digita /sair deslogar do chat</p>';
            echo "Nenhuma mensagem até o momento.";
        }

    } else {
        require_once("inc/nick.php"); // pede pra definir nick
    }
?>

JAVASCRIPT / JQUERY

function carregaMensagem() {

    var url = "verMensagem.php";
    jQuery.get(url, function(data){
        setInterval(intervaloMsg(data), 3000);

    }); 
}

function intervaloMsg(dados){
    $("#mensagens").empty().append(dados);
    //$("#mensagens").html(dados);

}

function enviar() {
    var url = "enviarMensagem.php";
    var mensagem = $("#mensagem").val();

    var enviando = $.post(url,{mensagem:mensagem});
    console.log(mesangem);
}

I thank you for your attention and apologize for any errors.

    
asked by anonymous 25.07.2018 / 21:16

1 answer

0

I think the error is in this line:

$sql = msql_query("SELECT * FROM mensagem");

The correct one would be

$sql = mysql_query("SELECT * FROM mensagem");

You also have an error in javascript

console.log(mesangem);

The correct one would be

console.log(mensagem);
    
25.07.2018 / 21:44