Page 1 of 1

insert value into field of another table on delete

Posted: Sun Sep 15, 2013 6:39 am
by lhardee

Hello,

I am working with 3 tables. One is called "interc" the second is called "redundancy" and the third is called "dual". Both redundancy and interc are similar tables with the exception of two fields in redundancy: the first is "higher_facility" and second is "keyvalue". The keyvalue field in redundancy is linked to a field in interc called "ID" The third table (dual) only has 1 field (D) with a value of D.
I would like to insert the letter "D" into the higher_facility field of redundancy when the user deletes a row in interc. Below is how I am trying to accomplish this task with no luck.

Inside intercinfo.php is the following code:

   function Row_Deleted(&$rs) {
   ew_ExecuteScalar("INSERT INTO redundancy(higher_facility) SELECT 'D' FROM dual WHERE NOT EXISTS(SELECT keyvalue FROM redundancy WHERE redundancy.keyvalue = ID)");
}

Any help would be appreciated.

lhardee


Re: insert value into field of another table on delete

Posted: Sun Sep 15, 2013 8:03 am
by mobhar

You should use "ew_Execute" instead of "ew_ExecuteScalar" if you want to execute the query without returning the value, such as DELETE, UPDATE, or INSERT INTO.

Use "ew_ExecuteScalar" only if you want to return the first column of the first row (usually SELECT query). Read "Some Global Functions" in the help file for further information and example.