PHP不会插入聊天消息

时间:2015-10-07 04:21:51

标签: php mysql

我有一个MySQL数据库,所有的,一些PHP插入值,其余的工作,但我的聊天没有。

我的主机不允许我查看MySQL错误日志,所以我不能通过它看到错误。

    <?php
session_start();
include 'default.php';
include 'SteamAuthentication/steamauth/userInfo.php';

$db = getDB();

if (!isset($_SESSION['steamid'])) {
    echo jsonErr('You are not logged in.');
    return;
}

$text = isset($_POST['text']) ? $_POST['text'] : null;

if (is_null($text) || strlen($text) === 0) {
    echo jsonErr('The required text for the message was not sent correctly or was left blank. Please refresh and try again.');
    return;
}

$steamUserID = $steamprofile['steamid'];

$stmt = $db->prepare('INSERT INTO chat (steamUserID, `text`, `date`, `time`) VALUES (:userid, :text, CURDATE(), CURTIME())');
$stmt->bindValue(':userid', $steamUserID);
$stmt->bindValue(':text', $text);
$stmt->execute();

echo jsonSuccess(array('message' => 'Message has been sent!'));
?>

作为一个注释,我的其他PHP文件可以很好地插入我的数据库,所以它不是数据库配置,我的代码是否有问题?

1 个答案:

答案 0 :(得分:1)

这是因为你有时会在列名称周围叹息,有时候不会,所以你现在有两个选择:

  1. 删除`符号

    $stmt = $db->prepare('INSERT INTO chat (steamUserID, text, date, time) VALUES (:userid, :text, CURDATE(), CURTIME())');
    
  2. 或者将其添加到表名和所有列名

     $stmt = $db->prepare('INSERT INTO `chat` (`steamUserID`, `text`, `date`, `time`) VALUES (:userid, :text, CURDATE(), CURTIME())');