Skip to main content

i have Table “project_sti” with field “id” as primary key, field “project_id” as a foreign key that references the primary key in the master table, field “sti_org_id” and field “role“.

So in PHPRUNNER, NO DUPLICATE ENTRY based on fields “project_id” AND “sti_org_id” AND “role” is Leader. Message will appear “Data already Have”


To enforce the rule in PHPRunner that prevents duplicate entries in the child table based on the combination of project_id, sti_org_id, and role is Leader, and to show a custom message “Data already exists”, you can follow these steps:

Using the Before Record Added/Updated Event

  1. Go to Events in PHPRunner for your project_sti table.
  2. Select the Before Record Added and Before Record Updated events.
  3. Add the following PHP code:

// Check for duplicate entry
$project_id = $values[‘project_id‘];
$sti_org_id = $values[‘sti_org_id‘];
$role = $values[‘role‘];

if($role === ‘Leader’)

{

$rs = DB::Query(“SELECT * FROM project_sti WHERE project_id= ‘$project_id‘ AND sti_org_id= ‘$sti_org_id‘ AND role = ‘Leader'”);

if($rs->fetchAssoc())

{

$message = “Data already exists.”;
return false; // This will stop the record from being added/updated

}

}