Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MySQL或PHP PDO错误_Php_Mysql_Pdo - Fatal编程技术网

MySQL或PHP PDO错误

MySQL或PHP PDO错误,php,mysql,pdo,Php,Mysql,Pdo,我得到一个: 警告:PDOStatement::execute()[PDOStatement.execute]:SQLSTATE[23000]:完整性约束冲突:第66行的/home/content/49/11554349/html/gb/dev/post.php中的1048列“classnum”不能为null 这也是它所指的php: public function CheckIfEmptyTutor($class,$classnum,$studentyear){ if(empty($c

我得到一个:

警告:PDOStatement::execute()[PDOStatement.execute]:SQLSTATE[23000]:完整性约束冲突:第66行的/home/content/49/11554349/html/gb/dev/post.php中的1048列“classnum”不能为null

这也是它所指的php:

public function CheckIfEmptyTutor($class,$classnum,$studentyear){

    if(empty($class) && empty($classname) && empty($studentyear)){
        echo "All fields are requiered to create the post.";
        return true;
    }
    else{
        return false;
    }           
}


public function TutorPost($class,$classnum,$studentyear){

    $stmt = $this->db->prepare("INSERT INTO tutors(class, classnum, studenyear) VALUES(?,?,?)");
    $stmt->bindParam(1,$class);
    $stmt->bindParam(2,$classnum);
    $stmt->bindParam(3,$studentyear);
    $stmt->execute();       
    if($stmt->rowCount() == 1){
        echo "Successfully posted!";
    }
    //For testing purposes.
    else{
        echo "Something went wrong.";   
    }
}
这些是我做的功能,一个是检查表单是否填写完整,另一个是将数据实际发布到数据库中

这就是我在html中调用它的方式

if(isset($_POST["submit"])){
    $class = $_POST["class"];
    $classnum = $_POST["classnum"];
    $studentyear = $_POST["studentyear"];
    $newpost = new UserPost();
    if(!$newpost->CheckIfEmptyTutor($class,$classnum,$studentyear)){
       $newpost->BookBoardPost($class,$classnum,$studentyear);
    }
}    

您的函数正在接受一个名为$classname的参数,但您正在绑定$classnum。由于没有$classnum,它可能将null传递到语句中

$stmt->bindParam(2,$classname);

您的函数正在接受一个名为$classname的参数,但您正在绑定$classnum。由于没有$classnum,它可能将null传递到语句中

$stmt->bindParam(2,$classname);

您的函数正在接受一个名为$classname的参数,但您正在绑定$classnum。由于没有$classnum,它可能将null传递到语句中

$stmt->bindParam(2,$classname);

您的函数正在接受一个名为$classname的参数,但您正在绑定$classnum。由于没有$classnum,它可能将null传递到语句中

$stmt->bindParam(2,$classname);

我认为函数调用有问题,请打印发送给函数的数据以确保它不为null。如果可以的话,请将其张贴在此处或一个提琴上

我认为函数调用有问题,请打印发送给函数的数据,以确保它不为空。如果可以的话,请将其张贴在此处或一个提琴上

我认为函数调用有问题,请打印发送给函数的数据,以确保它不为空。如果可以的话,请将其张贴在此处或一个提琴上

我认为函数调用有问题,请打印发送给函数的数据,以确保它不为空。如果您有错误,请将其张贴在此处或小提琴上

public function CheckIfEmptyTutor($class,$classnum,$studentyear){
    if(empty($class) && empty($classname) && empty($studentyear)){
这里应该是

public function CheckIfEmptyTutor($class,$classnum,$studentyear){
    if(empty($class) || empty($classnum) || empty($studentyear)){
您有错误:

public function CheckIfEmptyTutor($class,$classnum,$studentyear){
    if(empty($class) && empty($classname) && empty($studentyear)){
这里应该是

public function CheckIfEmptyTutor($class,$classnum,$studentyear){
    if(empty($class) || empty($classnum) || empty($studentyear)){
您有错误:

public function CheckIfEmptyTutor($class,$classnum,$studentyear){
    if(empty($class) && empty($classname) && empty($studentyear)){
这里应该是

public function CheckIfEmptyTutor($class,$classnum,$studentyear){
    if(empty($class) || empty($classnum) || empty($studentyear)){
您有错误:

public function CheckIfEmptyTutor($class,$classnum,$studentyear){
    if(empty($class) && empty($classname) && empty($studentyear)){
这里应该是

public function CheckIfEmptyTutor($class,$classnum,$studentyear){
    if(empty($class) || empty($classnum) || empty($studentyear)){


$classname
替换为
$classnum
并启用错误报告更改后,它仍然为
TutorPost()
调用
BookBoardPost()
?将
$classname
替换为
$classnum
并在更改后启用错误报告,它仍然为
TutorPost()
调用
BookBoardPost()
?将
$classname
替换为
$classnum
并启用错误报告更改后,它仍然为
TutorPost()
调用
BookBoardPost()提供相同的错误报告代码
?将
$classname
替换为
$classnum
并启用错误报告更改后,它仍然会为调用
BookBoardPost()
提供与
TutorPost()
相同的错误发布代码,因此问题可能出现在调用此函数之前。试着打印变量的值,看看是否有空值。回显所有变量,没有一个是空值。那么为什么调用函数时会出现问题?因此问题可能在调用此函数之前。试着打印变量的值,看看是否有空值。回显所有变量,没有一个是空值。那么为什么调用函数时会出现问题?因此问题可能在调用此函数之前。试着打印变量的值,看看是否有空值。回显所有变量,没有一个是空值。那么为什么调用函数时会出现问题?因此问题可能在调用此函数之前。尝试打印变量的值,看看是否有空值。回显所有变量,没有一个是空的,那么调用函数时为什么会出现问题?更改check函数中的&&to | |更改check函数中的&&to | |更改check函数中的&&to | |更改check函数中的&&to | |