Reputation: 35
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);
}
}
Upvotes: 0
Views: 71
Reputation: 24229
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)){
Upvotes: 0
Reputation: 142
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
Upvotes: 0
Reputation: 103155
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);
Upvotes: 3