I am trying to create a condition via php and mysql that a user can submit in a maximum of 5 submissions within a 24 hour formid time period
$max = 5;
$user = JFactory::getUser();
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('COUNT('.$db->qn('Username').')')
->from($db->qn('#__rs_submissions'))
->where($db->qn('FormId').'='.$db->q($formId))
->where($db->qn('Username').'='.$db->q($user->get('username')));
->where($db->qn('DateSubmitted').'>='.$db->q('DATE_SUB(NOW(), INTERVAL 1 DAY)'))
$db->setQuery($query);
$counter = $db->loadResult();
if ($counter >= $max){
$formLayout = '<p style="color:blue;">Oops !! Your Limits are Exhausted for 24 hours </p>';
}
}
Below are the values of the database table

Request does not comply with 24-hour date condition
->where($db->qn('DateSubmitted').'>='.$db->q('DATE_SUB(NOW(), INTERVAL 1 DAY)'))
can someone help and advise - what am I doing wrong and the solution to comply with the 24-hour limit
Edit
I assume - the counter ($ db-> qn ('DateSubmitted'). '> ='. $ Db-> q ('DATE_SUB (NOW (), INTERVAL 1 DAY)')) should be executed - along with the last recorded time should be the basis for calculating the 24-hour period, still uncertain because it cannot achieve the desired
Launching Bounty - can someone help with this.