Update a second table after updating the first one

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
bozape
User
Posts: 2

Update a second table after updating the first one

Post 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!


bozape
User
Posts: 2

Post 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;



mobhar
User
Posts: 11905

Post 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']."'";


Post Reply