mysql/php插入查询问题

mysql/php插入查询问题,php,mysql,Php,Mysql,我有以下的课堂教学方法 public function index() { $username = ''; $email = ''; $text = ''; $picture = ''; if (isset($_POST['submit'])) { $username = $_POST['username']; $email = $_PO

我有以下的课堂教学方法

public function index()
    {   
        $username = '';
        $email = '';
        $text = '';
        $picture = '';

        if (isset($_POST['submit']))
        {
            $username = $_POST['username'];
            $email = $_POST['email'];
            $text = $_POST['text'];
            $picture = $_POST['picture'];
            Task::create($username, $email, $text, $picture);
        }

        require_once(ROOT.'/views/site/index.php');
    }
我的表单发送值,我用
var\u dump($\u POST['username'])检查了它。

下面是
create()
方法

public static function create($username, $email, $text, $picture='1', $check_token=false)
    {
        $db = Db::connect();
        $query = 'INSERT INTO tasks (username, email, text, picture, check_token)
                 VALUES (:username, :email, :text, :picture, :check_token)';

        $result = $db->prepare($query);
        $result->bindParam(':username', $username, PDO::PARAM_STR);
        $result->bindParam(':email', $email, PDO::PARAM_STR);
        $result->bindParam(':text', $text, PDO::PARAM_STR);
        $result->bindParam(':picture', $picture, PDO::PARAM_STR);
        $result->bindParam(':check_token', $check_token, PDO::PARAM_STR);

        $result->execute();
    }
我的数据库连接正确,因为我的身份验证系统正常工作。但是这个查询没有插入任何内容。我的代码有什么问题?
谢谢您的帮助。

如果是关键字,则必须转义字段名。因此,您必须像这样在fiel dname文本周围加上记号

   $query = 'INSERT INTO tasks (username, email, `text`, picture, check_token)
             VALUES (:username, :email, :text, :picture, :check_token)';

是否返回了错误或一切正常?
stmt->errorInfo()
function@HonzaRydrych请注意:第21行的/home/hue/test/controllers/SiteController.php中的文本通知:第22行的/home/hue/test/controllers/SiteController.php中的图片通知:未定义索引`尝试将查询置于双引号中,而不是单引号中。
$query=“queryhere”表单未知。为什么?它不是一个保留字,它是一个关键字,这不是问题所在,它是“有此警告通知:未定义索引:第21行/home/hue/test/controllers/SiteController.php中的文本通知:未定义索引:第22行/home/hue/test/controllers/SiteController.php中的图片”–Alexandr Krivosheev 10分钟前”测试是一个类似int的数据类型,char varchar,textsure,但对于OP在评论中明确指出的真正问题,我不同意。同样,手册中
文本
旁边没有
(R)
,因此此处不需要转义。仍然没有结果,请使用thxtry@Fred-你说得对