PDO将整个插入行发送到数据库

时间:2017-05-26 22:54:53

标签: php ajax database pdo

当我发送消息时没有发送消息,假设将消息发送到数据库的行发送插入行代替...我不知道如何解决它。

http://imgur.com/a/4njs1

http://imgur.com/a/r1giu

function onsend(e){
    if (e.keyCode == 13) {
        document.forms["sendchat"]["namechat"].value = id;
        var username = document.forms["sendchat"]["namechat"].value;
        var message = document.forms["sendchat"]["chat"].value;
        if(message == ''){

        }else
        $.post( ('php/friend/chat_send.php'), $('#sendchat :input').serializeArray(),
            function(data){
                $('#chats').html(data);
              setTimeout(function(){
                    document.getElementById("chat").value = '';
                    refresh_social()
                chat_refresh()
              }, 100);
                setTimeout(function(){
                var element = document.getElementById('chat-panel');
                element.scrollTop = element.scrollHeight;
            }, 150);
        });
    };
};



<?php
session_start();
if(isset($_SESSION['users']) == ""){
echo '<script type="text/javascript">','index();','</script>';
}

require '../../php/dbConnect.php';

if (isset($_POST['namechat'])) {
$username = $_POST['namechat'];
}
if (isset($_POST['chat'])) {
$chat = $_POST['chat'];
}
$user = $_SESSION['users'];
$image = $_SESSION['image'];

      $chat = 'INSERT INTO `chat` (username_send, username_receive, image, chat)VALUES (?, ?, ?, ?)';
      $fetch_chat = $conn->prepare($chat);
      $fetch_chat->bindParam(1, $user, PDO::PARAM_STR);
      $fetch_chat->bindParam(2, $username, PDO::PARAM_STR);
      $fetch_chat->bindParam(3, $image, PDO::PARAM_STR);
      $fetch_chat->bindParam(4, $chat, PDO::PARAM_STR);
      $fetch_chat->execute();
?>

0 个答案:

没有答案