This topic is locked
[SOLVED]

 Update two fields from list page via button

8/15/2017 11:40:08 PM
PHPRunner General questions
H
Hertz2P author

I can successfully update one field (a checkbox) on all selected records on the list page, but when trying to get the second one to work, it doesn't. I don't know if it's because it's the second field or if it's a date field, but I get 0/0/0000 as a result. What's wrong with my code:



global $dal;



while ( $data = $button->getNextSelectedRecord() ) {

$sql = "Update TimeCard set supervisorApproved='1' where id=".$data["id"];

CustomQuery($sql);

$sql = "Update TimeCard set dateApproved='Date()' where id=".$data["id"];

CustomQuery($sql);

}

$result["txt"] = "Records were updated.";
H
Hertz2P author 8/15/2017

I realize that it's a SQL statement and that Date() is probably the issue, but would like to put current date in that field when the button is pressed. Is there a way to do this?

H
Hertz2P author 8/16/2017

Never mind.. Here's the solution:



global $dal;



while ( $data = $button->getNextSelectedRecord() ) {

$sql = "Update TimeCard set supervisorApproved='1' where id=".$data["id"];

CustomQuery($sql);

$sql = "Update TimeCard set dateApproved=now() where id=".$data["id"];

CustomQuery($sql);

}

$result["txt"] = "Records were updated.";