This topic is locked

Unique records and CAPITALS

5/4/2007 2:20:59 PM
PHPRunner General questions
F
funkfish author

Hello,
I wanted to know if it is possible to have the data to be entered verified to see if there is already a duplicate entry entered. Also, make sure that the data entered is only in capitals, or convert always to capitals....
Many thanks!

Sergey Kornilov admin 5/7/2007

Use BeforeAdd/BeforeEdit events for this purpose.
See sample action "Check if record exists".
To convert data to upper case use strtoupper() function:

$values["FieldName"] = strtoupper($values["FieldName"]);
F
funkfish author 5/9/2007

Use BeforeAdd/BeforeEdit events for this purpose.

See sample action "Check if record exists".
To convert data to upper case use strtoupper() function:

$values["FieldName"] = strtoupper($values["FieldName"]);


  1. Where do I put the convert to capitals code?
  2. I entered the following for the custom code:

    function BeforeRegister(&$values)

    {

    global $conn;

    $strSQLExists = "select * from pcba where upc='".$values["upc"]."'";

    $rsExists = db_query($strSQLExists,$conn);

    $data=db_fetch_array($rsExists);

    if($data)

    {

    echo "UPC already exists!!";

    return false;

    }

    else

    {

    return true;

    }

    }
    When I try entering a duplicate it allows me and does not prompt me "UPC already exists!"

    This code is enterd in "Table Events / Add Page / Before record added & Before record updated"
    Thanks in advance!!!

Sergey Kornilov admin 5/9/2007

I'm talking about BeforeAdd/BeforeEdit events while you trying to use it in BeforeRegister event.

F
funkfish author 5/9/2007

I'm talking about BeforeAdd/BeforeEdit events while you trying to use it in BeforeRegister event.


Sorry....the actual code is the following:
function BeforeAdd(&$values)

{

global $conn;

$strSQLExists = "select * from pcba where upc='".$values["upc"]."'";

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);

if($data)

{

echo "UPC already exists!!";

return false;

}

else

{

return true;

}

}
Do I need to add every field if I only want to search for duplicates in the upc field?

The database is pcba and there are 10 field in total.
Thanks again!

Sergey Kornilov admin 5/9/2007

This code looks correct and you don't need to add all fields if you only search for duplicates in UPC field.

F
funkfish author 5/10/2007

This code looks correct and you don't need to add all fields if you only search for duplicates in UPC field.


Working now....thank you!