SQLSTATE [23000]:违反完整性约束:1048列"post"不能为空 [英] SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'post' cannot be null

查看:150
本文介绍了SQLSTATE [23000]:违反完整性约束:1048列"post"不能为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码,但是当我尝试这些代码时,我得到了:

I have this codes but when I try these code I am getting:

SQLSTATE [23000]:违反完整性约束:1048列"post"不能为空 这个错误.

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'post' cannot be null this error.

我找不到任何解决方案.我尝试了另一个可以正常工作的功能,但是这个功能不起作用.

I could not find any solution. I tried another functions which are work they are worked but this one is not work.

?>
<form method="post">
Buraya yaz <br><textarea style="resize:none" name="post"></textarea> <br><input type="submit" value="Gönder">
</form>

<?php 
if(empty($_POST['post'])){
echo 'you should fill the area.';
exit;
}
if (empty($errors) === true) {
$users->sendpost($post);
}
?>

public function sendpost($post){
$query  = $this->db->prepare("INSERT INTO `posts` (`post`) VALUES (?) ");
$query->bindValue(1, $post);
try{
$query->execute();
}catch(PDOException $e){
die($e->getMessage());
}   
}

推荐答案

插入$ post = $ _POST ['post'];

insert $post = $_POST['post'];

$post = $_POST['post'];

if(empty($_POST['post'])){
echo $errors[] = 'you should fill the area.';
}
if (empty($errors) === true){
$users->sendpost($post);
}

这篇关于SQLSTATE [23000]:违反完整性约束:1048列"post"不能为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆