Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialLeslie Toh
Front End Web Development Techdegree Student 496 PointsError!: SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: projects.category
Had this error on this code.
function add_project($title, $category){ include 'connection.php';
$sql = 'INSERT INTO projects(title, category) VALUES(?, ?)';
try{
$result = $db->prepare($sql);
$result->bindValue(1, $title, PDO::PARAM_STR);
$result->bindValue(1, $category, PDO::PARAM_STR);
$result->execute();
}catch (Exception $e){
echo "Error!: " . $e->getMessage() . "<br />";
return false;
}
return true;
}
2 Answers
Chris Shaw
26,676 PointsHi Leslie Toh,
You have a simple oversight which is you're trying to assign both your variables to the first placeholder, simply change it to the below so you your variables to indexes 1 & 2.
$result->bindValue(1, $title, PDO::PARAM_STR);
$result->bindValue(2, $category, PDO::PARAM_STR);
Happy coding!
Renzo Salvador
523 Pointsfunction add_project($title, $category){ include 'connection.php';
$sql = 'INSERT INTO projects(title, category) VALUES(?, ?)';
try{
$results = $db->prepare($sql);
$results->bindValue->(1, $title, PDO::PARAM_STR);
$results->bindValue->(2, $category, PDO::PARAM_STR);
$results->execute();
} catch (Exception $e){
echo "Error!: " . $e->getMessage() . "<br />";
return false;
}
return true;
}
?>
Can anyone spot an error? I get Error 500
Leslie Toh
Front End Web Development Techdegree Student 496 PointsLeslie Toh
Front End Web Development Techdegree Student 496 PointsThanks Chris