I have Created a simple Item Master Form my fields are Id,Name and Price , I want to validate duplicate Name , can anyone suggest me how to validate duplicate name which is not accepting and showing error message “Duplicate Item Name” , my Database is mysql and table name Itemmaster,
you have 2 options:
1.- use and ajax on change event (wouldnt recommend it)
2.- use the onvalidate event of the form where you check the name and use sc_error to display the error message and avoid the saving of the new item.
Regards
Thanks !
i am using both option but when i try to edit old items then also shown error message
my OnValidation Code :
sc_select(my_data, “select name,id from itemmast”);
$eDuplicate=0;
if ({my_data} === false)
{
echo “Access error. Message =”. {my_data_erro};
}
else
{
while (!$my_data->EOF)
{
if ({name}=$my_data->fields[0] ) {
$eDuplicate=1;
}
$my_data->MoveNext();
}
$my_data->Close();
}
if ($eDuplicate=1 ) {
sc_error_message("Duplicate Item Name ");
}
Regards
there is your error man, and to be honest is not optimal. Your query should be something like
$query = "SELECT *
FROM itemmast
WHERE itemname = '" . {itemname} . "' AND id <> " . {id}; // in the query you look for the name where the id is different to the current ID = in case is new the currentID should be = 0
sc_lookup( my_data, $query)
if ( isset( {my_data[0][0]} ) ) // if you found data then you found the name. therefore you display the error.
{
sc_error("you already captured that item... silly rabbit!!!!!");
}
Thank you very much.
but when i update old record show some error
Error updating database - record not found
Well lemme know if I can be of help.
Regards
why in 'if you use = and not ==