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 trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Julie Dowler](https://secure.gravatar.com/avatar/dd1c9e540e41119e01c3ab5895271cab?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Julie Dowler
7,851 PointsStuck again!
CRUD OPERATIONS WITH PHP
Challenge Task 1 of 1
Before adding a date to a MySQL database, we want to make sure that it's in the proper format: YYYY-MM-DD
Split the date into its 3 parts using explode(), with the dash (-) character.
Check that each part is the proper number of digits.
Check that the entered value is actually a valid date.
If any of the steps 1-3 fail, return false. If the date makes it through the validation, return true.
I keep getting this error:
Bummer! Make sure you return true for a valid date. Remember the function checkdate returns true if valid and false if not.
<?php
function valid_sql_date($date) {
$exploded_date = explode('-',$date);
if (count($exploded_date != 3) ||
strlen($exploded_date[0]) != 4 ||
strlen($exploded_date[1]) != 2 ||
strlen($exploded_date[2]) != 2 ||
!checkdate($exploded_date[2], $exploded_date[1], $exploded_date[0]) )
{
return false;
} else {
return true;
}
}
2 Answers
![lol cupid](https://uploads.teamtreehouse.com/production/profile-photos/10405142/micro_Hacker_logo_.jpg)
lol cupid
6,174 Points- check your count function... So, you need to code Comparison Operator outside parenthesis...
- Ordering of checkdate function is (Month, Day, Year)... So, you need to pass [1], [2], [0] orderly...
![Julie Dowler](https://secure.gravatar.com/avatar/dd1c9e540e41119e01c3ab5895271cab?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Julie Dowler
7,851 PointsOk, I answered my own question here. I needed to set a variable to true or false, then return the variable. Apparently you can't return true or return false.