0

Im getting a:

Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'classnum' cannot be null in /home/content/49/11554349/html/gb/dev/post.php on line 66

This is the php it refers too:

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.";   
    }
}

Those are the functions I made, 1 is to check if the form is completely filled out, the other to actually post the data on the database.

And this is how im calling it in the 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);
    }
}    
3
  • 2
    replace $classname with $classnum and enable error_reporting Commented Dec 1, 2013 at 20:38
  • after changing it, it still gives me the same error Commented Dec 1, 2013 at 20:50
  • Posted code for TutorPost( ) calling BookBoardPost( )?? Commented Dec 2, 2013 at 9:53

3 Answers 3

3

Your function is accepting a parameter called $classname but you are binding $classnum. Since there is no $classnum it is probably passing null into the statement.

$stmt->bindParam(2,$classname);
Sign up to request clarification or add additional context in comments.

2 Comments

So the problem could be before the call to this function. Try printing the values of the variables and see if any are null.
echoed all of them, none are null so why is there a problem when calling the function?
0

I think the function call has a problem , print out the data you sent to the function to make sure it's not null . Post it here or an a fiddle if you can

1 Comment

Change the && to || in the check function
0

you have error:

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

here should be

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.