Page 1 of 1

Update a second table after updating the first one

Posted: Tue Aug 27, 2013 8:58 am
by bozape

Hi!

I already read some post about the same situation but still get some error and can't find why.

I have 2 tables, FINAL and SETTLER
On FINAL table there are some fields like CONTROL, US_NAME and IDCAT between others fields
On SETTLER I have SURNAME,IDCAT and others.

So in the "server side" in the "row_updated" event of the FINAL table I am using this code to update the SETTLER table:


function Row_Updated($rsold, &$rsnew) {
$queryset = "UPDATE settler, final SET settler.idcat = final.idcat WHERE settler.surname = final.us_name and final.control = ".$rsnew['control'];
$updsettler = ew_Execute($queryset);
}


I test the SQL sentence in phpmyadmin for example and it is working fine but from the phpmaker I get the error:

Failed to execute SQL. Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

Any ideas?

Thanks!


Re: Update a second table after updating the first one

Posted: Tue Aug 27, 2013 9:13 am
by bozape

Well found my self another solution.
No idea why the SQL statement is not working but now it works in this way


$queryset = "UPDATE settler SET settler.idcat = ".$rsnew['idcat']." WHERE settler.surname = '".$rsnew['us_name']."'";
$updsettler = ew_Execute($queryset);
return TRUE;



Re: Update a second table after updating the first one

Posted: Tue Aug 27, 2013 10:05 am
by mobhar

$queryset = "UPDATE settler, final SET settler.idcat = final.idcat WHERE settler.surname = final.us_name and final.control = ".$rsnew['control'];

should be:
$queryset = "UPDATE settler, final SET settler.idcat = final.idcat WHERE settler.surname = final.us_name and final.control = '".$rsnew['control']."'";