I mean, i’d be checking to see if $rack_id was set in the second if, but yeah, the code as listed should work unless something in the intervening code removes it (or if it’s on a different code path).
I’ve not seen the form before this, but if it contains an input named rack_id it should always be set, unless it’s a checkbox. So that would make the test redundant anyway (certainly doing it twice is).
Maybe check for empty instead.
If they didn’t change this in one of the latest PHP versions, that is wrong. There is nothing like a block scope in PHP. All variables declared in a block can be accessed from outside also.
(But my PHP knowledge is also long time not updated)
Not quite true. There is no general block scope, but user-defined functions are a separate scope. They can access the global scope with the global declaration at the start of their block, but otherwise, all variables in a function are local-scope.
I’ll be a bit more basic. Why are you doing this at all?
Based on the filename - add_power_strip_engine.php, this is part of some Create operation. If this operation requires a logged in user, you should never display the form or run any of the form processing code without first having a logged in user, not attempt to provide a way for the user to login after the fact.
Also, since post data doesn’t persist outside the request it was submitted with, using a post value as part of a link won’t do any good, since the visitor will need to fill in and resubmit the form after logging in.