check exist

dave114 14 May, 2015
Hi, I'd like create form. I created:
Name
surname
Email
ID number
I would like to make the system checks the number in the database whether there is
Pls, help me😉
Best regards
GreyHead 14 May, 2015
Hi dave114,

You can use a DB Read action to do the check; or more simply use an Event Switcher action with a MySQL query:
<?php
$db = JFactory::getDBO();
$query = "
    SELECT COUNT(*)
        FROM `#__your_table`
        WHERE `id` = '{$form->data['id']}' ;
";
$db->setQuery($query);
$count = $db->loadResult();
if ( $count > 0 ) {
  return 'fail';
} else {
  return 'success';
}
?>

Bob
This topic is locked and no more replies can be posted.