Fix theexpected value of getNewActionId() that was mistakenly set.

When registered action is empty, the function returns one.
Fix a syntax error in the SQL statement that doesn't have the field for the order.