Forums

Check if field content already exist

giusebos 04 Mar, 2016
Hi all,
I need some help, I have created a product registration form.
The form is working perfectly can send capture data on database,
However, to avoid recording 2 times the same product, I need to check whether the item entry exists on database.

I attach backup my form

name table: TipologiaUrbanistica
name field1: idTipologiaUrbanistica
name field2:tipologiaUrbanistica
giusebos 04 Mar, 2016
This is the code used in event switcher

<?php  
    $db = JFactory::getDbo();
    $query = "
    SELECT COUNT(*)
    FROM `TipologiaUrbanistica`
    WHERE `tipologiaUrbanistica` = '{$form->data['tipologiaUrbanistica']}' ;
    ";
    $db->setQuery($query);
    $db->query();
    $num_rows = $db->getNumRows();
    if ($num_rows==0){
        return "success";
        }else{
        return "fail";
    }
    ?>


unfortunately I can not make it work
you could look at my file?

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