Possible to check fields against current records?

libraguy78 15 Apr, 2010
Back again! Hoping to get this final piece fixed, and have the form system running I got.

I've searched through over 40 pages of posts, and have yet to come up with how or if this is possible. So I'll lay it out what I need.

The form is complete, and is storing data properly. What I need to do is make sure that a duplicate entry isn't added. And I believe this is done in the PHP verification box?

I need it to check if there is a record that matched the FIRST_NAME and LAST_NAME fields, and if the APPROVED_BOX = TRUE. This sounds simple, but I haven't found anything that relates to this.

If the matching FIRST_NAME and LAST_NAME does have a "TRUE" APPROVED_BOX, then the form shouldn't submit, and if possible, tell them they cant submit another application.

I hope I was clear enough on this.😟 My skills in PHP are very light. Thank you in advance.
GreyHead 15 Apr, 2010
Hi libraguy78,

The code will be something like this:
<?php
$db =& JFactory::getDBO();
$first_name =& JRequest::getString('FIRST_NAME', '', 'post');
$last_name =& JRequest::getString('LAST_NAME', '', 'post');
$query = "
  SELECT COUNT(*) 
    FROM`#__some_table_name`
    WHERE `FIRST_NAME` = '$first_name' 
      &&  `LAST_NAME` = '$last_name' 
      &&  `APPROVED_BOX` = 'TRUE' 
";
$db->setQuery($query);
$count = $db->loadresult();
if ( $count > 0 ) {
  return "This name is already in use";
}
?> 
Not tested and will need debugging!
You'll need to check input and column names and put in the correct table name.

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