PHP raises an error because the pointer is invalid (there is no "1" offset if you only have 1 record, right?). You are expecting that to cause the <b>while</b> check to fail. It will, but the index error is raised first.
Change
<b>
while ($data = pg_fetch_object($login_result, $row))</b>
to
<b>
while ($data = @pg_fetch_object($login_result, $row))</b>
The @ will mute the index error and the <b>while</b> check will fail just as you expect it to.
-- Rich