Show/Hide Toolbars

Navigation: Advanced topics > Events > Predefined actions

PHPrunner32x32     PHPRunner manual


Check if specific record exists

Scroll Prev Next More

 

To check if a specific record exists use Check if specific record exists action.

step11-1-4

yellowbulbNote: Change the values listed in red to match your specific needs.

//**********  Check if specific record exists  ************

$strSQLExists = "select * from AnyTable where AnyColumn='SomeValue'";

$rsExists = db_query($strSQLExists);

$data=db_fetch_array($rsExists);

if($data)

{

  // if record exists do something

}

else

{

  // if dont exist do something else

}

Example

Let's assume we need to check the uniqueness of the entered SSN number. Use the following code in the Before record added event:

//**********  Check if specific record exists  ************

$strSQLExists = "select * from Clients where SSN='" . $values["SSN"] . "'";

$rsExists = db_query($strSQLExists);

$data=db_fetch_array($rsExists);

if($data)

{

// if record exists do something

$message = "SSN " . $values["SSN"] . " already exists."

return false;

}

else

{

// if dont exist do something else

}