This topic is locked

Help on how to prevent the entry of duplicate values...

12/20/2012 5:41:16 AM
PHPRunner General questions
D
DUKE author

I have a database in which the client enters waybill information.
The values in the field 'waybill no' needs to be unique. I have had one or two cases where the client enters the same waybill twice.
I need to do the following:
When the client has finished entering the waybill information, I need to check if the 'waybill no' has already been entered into the database. If it has, an error message has to be displayed. If not, the information is saved.

R
rgfischerjr 12/20/2012

You can handle this in the database by setting the field to unique (or using the waybill as a primary key).

C
cgphp 12/20/2012

In the "Before record added" event, enter the following code:

$rs = CustomQuery("SELECT waybill FROM your_table_name WHERE waybill ='". $values['waybill']."'");

$record = db_fetch_array($rs);
if($record)

{

$message = "The waybill number already exists. Please, try again."

return false;

}
return true;


Replace waybill with the real name of the waybill field.